First time using Cake and its containable behaviour, but it's not working as expected ... or at all.
I'm trying to obtain a list of accessories for a product. Product model HABTM products (alias 'ProductRelation'). Join table is products_products which has two product ids - product_id and related_id. It's against this I want to pull the list of accessories (products driven from the related_id column) for a given product_id
In my Product model, I've added $actsAs = array('Containable');
And in my controller, a quick test of containable using reference from the cookbook fails to contain products at all, even without conditions.
debug($this->Product->find('all', array('contain' => 'ProductRelation')));
.. returns an array of every product in the db, with ALL related models - images, content tabs, ratings, reviews, pricing, etc I haven't tried applying any 'conditions' against this because the call as written should limit data to the product and it's ProductRelation data, according to the cookbook ...
Any tips?
'contain' => array('ProductRelation')
– Tim Joycevar $actsAs = array( 'Containable' );
– Barry ChapmanIn my Product model, I've added $actsAs = array('Containable');
He has it onProduct
model. I stated to add it in the AppModel - sinceContainable
needs to be active on the model being contained, and not simply the one doing the containing. Adding it toAppModel
will naturally make it available to all models inheritingAppModel
. – Barry Chapman