Left Join With Findall


Say I have a model Cars, and a model Adverts which tells me on which newspaper I have published the advert for a car. A car can be on several Adverts at the same time. Say I want a list of Cars on the news, every car repeated for every (i know makes no sense but I need this way).

So the query would be something like this:

SELECT cars.* FROM cars JOIN adverts on cars.id = adverts.car where advert.date = A

This way I can obtain several times the same car, and this is what I need.

How do I translate this to Yii?

In Adverts I make a relation BELONGS_TO for car->cars.id

In Cars I make a relation HAS_MANY adverts.

my criteria is:

$cdb->with = array(


        //        'together'=>true,


                'condition'=>'a.date = :A',





The problem is that I get every car only ONCE, even if it is published in several adverts!

How can I get "duplicate" Cars for every advert I have?


as a workaround I did this way:

if (count($a = Adverts::model()->findAll(array(


                'params'=>array(':car'=>$this->id))))) {

            $car = array (); 

            foreach ($a as $cgp) 

                $car [] = $cgp->rel_car;

            return $car;


You can try to set HAS_MANY in both models…