Please help me with this question. I want to do a query to get dataset and related authors like this,
$models = Dataset::model()->with(‘authors’)->findByAttributes(array(‘name’=>$_GET[‘name’]));
name is in the authors table but not dataset table. But it does not work.
What did I do wrong or how could I fix this problem?
Thanks!
ronald58
(Yii)
2
Try :
$models = Dataset::model()->with('authors')->findAllByAttributes(array('authors.name'=>$_GET['name']));
qianggan
(qianggan@msn.com)
3
-
Did you set relationship between authors and dataset? If not this should be the first step when you create model dataset
-
findByAttributes and findAllByAttributes will return different result. If you want to return CActiveRcords[], use findAllByAttributes like Ronald did.
See more detail in http://www.yiiframework.com/doc/guide/1.1/en/database.arr