Thanks for the reply. Found out shortly after I posted the question
that yeah, Cake doesn't create joins for hasMany by default - pretty
silly, why is that?
Anyway, ended up writing some code in the Model itself so I can always
call a method to fetch with a forced join. Not 100% certain if this is
the best way of doing it (given someone wrote the linkable behavior)
but am open to criticism and your feedback. Here's the code in the
ProductVariation model, may help someone with the same issue -
>>> BEGIN CODE >>>
function getProductVariation($id, $qty = false) {
$this->unbindModel(array('belongsTo'=>array('Product')));
$productVariation = $this->find('first', array(
'fields' => array(
'ProductVariation.*',
'Product.*',
'UnitType.*',
),
'contain' => array(
'Product'
),
'conditions' => array(
'ProductVariation.id' => $id
),
'joins' => array(
array(
'table' => 'products',
'alias' => 'Product',
'conditions' => array(
'Product.id = ProductVariation.product_id'
)
),
array(
'table' => 'unit_types',
'alias' => 'UnitType',
'conditions' => array(
'Product.unit_type_id = UnitType.id'
)
)
)
));
$this->reBindProducts();
return $productVariation;
}
function reBindProducts() {
$this->bindModel(array(
'belongsTo' => array(
'Product' => array(
'className' => 'Product',
'foreignKey' => 'product_id',
)
)
));
}
>>> END CODE >>>
Cheers,
Thanks for your help again guys, will check out the linkable behavior
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment