0
votes

I have been banging my head on the wall over this. I have a model Sku that belongs to model Purchase. My AppModel has $actAs=array('Containable') and $recursive=-1

Inside SkuController, when I do $this->Sku->find('all', array('contain' => 'Purchase')); I don't get Purchase. I have searched many old questions here and elsewhere on Internet but just can't seem to resolve this. To check if Containable behavior is being loaded, I edited ContainableBehavior.php in lib\Cake\Model\Behavior to make it an invalid php file but that didn't produce any errors. What the heck is wrong!!

Here's the SQL from debug:

SELECT Sku.id, Sku.purchase_id, Sku.item_id, Sku.upc, Sku.quantity_avail, Sku.per_unit_price_amt, Sku.do_not_delete, Sku.created, Sku.modified, (concat('SK',lpad(Sku.id,8,'0'))) AS Sku__idFormatted FROM sellble.skus AS Sku WHERE 1 = 1 ORDER BY Sku.id desc

CakePHP ver: 2.4.4

1
Is Sku model associated with Purchase?Guillermo Mansilla
Are you using actAs or the proper actsAs variable? Are your variable assignments public, i.e. public $actsAs = array('Containable');? If you remove the recursive setting, does the purchase data return in your find (just to check the association)? If you create a reflection of your model, does it carry the array containing 'Containable' in the actsAs variable?Scott Harwell

1 Answers

1
votes

Not sure if this is different across versions but I have always specified the contain within an array and that works fine for me.

$this->Sku->find('all', array('contain' => array('Purchase')));

Or for mapping only the fields or conditions you want:

$this->Sku->find('all',
     array('contain' => array(
         'Purchase' => array(
             'fields' => Purchase.name
             'conditions' => array(
                  Purchase.name = 'somename'
                  )
             )
         )
     )
);