heyhoo
(Mark)
June 6, 2010, 8:31pm
1
I have the following tables:
Campaigns
…
Build
…
BuildParams
…
One campaign has many builds and a build has many buildparams.
How can I get all the buildparams based on a campaign id?
I have the following tables:
Campaigns
…
Build
…
BuildParams
…
One campaign has many builds and a build has many buildparams.
How can I get all the buildparams based on a campaign id?
Make sure to set up your relations in your objects, and then you can call
$criteria = new CDbCriteria();
$criteria->condition = ‘campaign_id = :campaign_id’
$criteria->params = array(’:campaign_id’ => $campaign_id);
then you can do either
Build::model()->with(‘Campaigns’, ‘BuildParams’)->findAll($criteria);
And you should get everything from all three tables. You can find more info on setting up relationships here:
http://www.yiiframework.com/doc/guide/database.arr
Please let me know if you still have trouble after reading these docs and I can try to help you with your relationships as well.
Corey
heyhoo
(Mark)
June 9, 2010, 8:02pm
3
Hi Corey,
thanks for your answer.
Can you explain how to set up the relations in the objects.
It is not really clear to me how to do this.
Thanks!
Raoul
(Manu34)
June 9, 2010, 9:08pm
4
hi heyhoo,
did you check this chapter from the guide ?
Note that if you use yiic (or even better : gii ) to generate automatically your model classes, relations are automatically created. Then take a look at the relation method to understand better.
Hope this helps
heyhoo
(Mark)
June 9, 2010, 11:01pm
5
Thanks for the answers. I have figured it out