I have a Blog model that has defined var $hasMany=array("Comment");
How can i apply a filter on the Comments to select only the Blog items that match a certain Comment category?
If, in the Blog model, i do
$this->recursive=2;
$this->hasMany=array("Comment"); //in Comment i have $belongsTo("Blog")
return $this->find("all",array("conditions"=>array("Comment.comment_type_id"=>123)));
i get an error that says Unknown Comment.comment_type_id column because Cake does not make the join.
I think this is a rather common issue so i believe simple to solve but i can't find a good way
$this->bindModel(array(
'hasMany' => array(
'Comment' => array(
'conditions' => array('Comment.comment_type_id' => 123)
))));
$this->find('all');
or if the Model is already binded with comment use :
$this->hasMany['Comment']['conditions'] = array('Comment.comment_type_id' => 123);
$this->find('all');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With