Error when retrive data with using relation

Hi,

Im trying get all rows from my table "Product", but my model has one relation:


'sites' => array(self::MANY_MANY, 'Site', 'product_site(product_id, site_id)'),

And when i try get all data from the table using "findAll", i have a strange behavior. Example:




THIS CODE RETRIVE ALL ROWS CORRECTLY


$list = Product::model()->with('sites')->findAll();

[/code]




THIS GENERATE A QUERY WITHOUT THE RELATION - ONLY BECAUSE I PUT THE CRITERIA THAT CONTAINS SOME CONDITIONS TO "WHERE"


$list = Product::model()->with('sites')->findAll($criteria);

[/code]

What can be the problem?

My structure is:

  • Product (id)

  • Site (id)

  • ProductSite (product_id, site_id)

I have to list all products that have relation with site with id 0 or 1 (product_site.site IN 0,1)

Did you try this?




...

$criteria->together = true;

$criteria->condition = 'sites.id IN (3,4)';

...



/Tommy

Hi,

The "together" option solve the problem.

Ty.