Monday, October 20, 2014

Issue with deep associations - cake 3.0

I have the following in my Products controller:

        $creditIntermediaries = $this->Products->CreditIntermediaries->find('list', ['valueField' => 'persona.other_names'])
            ->contain('Personas')
            ->toArray();

When I go to the page that uses it, I get the following error:

Error: CreditIntermediaries is not associated with Personas


However, if I load the CreditIntermediaries model model manually using
         $this->loadModel('CreditIntermediaries');

It all works fine.

Products Table belongsToMany CreditIntermediaries, and vice versa.

The ProductsTable contains the following:

        $this->belongsToMany('CreditIntermediaries', [
            'foreignKey' => 'product_id',
            'targetForeignKey' => 'credit_intermediary_id',
            'joinTable' => 'credit_intermediaries_products',
            'className' => 'ProductManager.CreditIntermediaries',
        ]);

And CreditIntermediariesTable has:

        $this->belongsToMany('Products', [
            'foreignKey' => 'credit_intermediary_id',
            'targetForeignKey' => 'product_id',
            'joinTable' => 'credit_intermediaries_products',
            'className' => 'ProductsManager.Products'
        ]);
        $this->belongsTo('Personas', [
            'foreignKey' => 'persona_id',
        ]);

any thoughts? Loading the model works, but it doesn't feel right.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: