phpdevmd
(Phpdevmd)
July 9, 2009, 1:17pm
1
Hello,
Is there a way to find ActiveRecords by relations key match?
I have model
class Business extends CActiveRecord
{
public function relations()
{
return array(
'addresses'=>array(self::HAS_MANY,'BusinessAddress','businessId'),
)
}
}
What I'm trying to do is:
$businesses=Business::model()->with('addresses')->findAll("addresses.address1=?",array('Yii Street'));
So, basically I need all business with addresses where address1='Yii Street'.
address1 is a field of BusinessAddress table.
Thanks
qiang
(Qiang Xue)
July 9, 2009, 2:38pm
2
you need to use: with(…)->together() ->findAll…
phpdevmd
(Phpdevmd)
July 9, 2009, 4:32pm
3
Here is how it worked:
$businesses=Business::model()->with('addresses')->together()->findAll("t1.address1=?",array('Yii Street'));
t1
is there a way to use something instead of t1 ? maybe a method or?
Thanks!
qiang
(Qiang Xue)
July 9, 2009, 8:45pm
4
You need to set 'alias' option in the relation declaration. Otherwise, it will use an automatically generated alias.
phpdevmd
(Phpdevmd)
July 10, 2009, 6:00am
5
Thank you qiang.
Your participation in forum's life and your help was always impressing me.