Find ActiveRecord by it's relations key match?

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

you need to use: with(…)->together()->findAll…

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!

You need to set 'alias' option in the relation declaration. Otherwise, it will use an automatically generated alias.

Thank you qiang.

Your participation in forum's life and your help was always impressing me.