Need Help With Conditional Relational Active Record

I’m putting together a multi-store e-commerce site that has different descriptions for some of the items, depending on the store.

Here is a basic layout of the tables:









The relation I have setup right now in Product is:

'description'=>array(self::HAS_ONE, 'ProductDescription', 'product_id',




This works, but only grabs the description for Store 1. Store 1 is the default store that has all descriptions.

The problem is when I switch this to store_id = 2. I need this relation to check to see if there is a product_description available for a particular product in Store 2, and if it does not find one, default back to Store 1.

Can someone help me figure out how to write that?


I’ld work with:

  1. Order by store_id DESC

  2. condition ‘store_id IN (1,:current_store)’ , ‘params’=>(’:current_store’=>[whatever var is the current store value]).

Brilliant in its simplicity. Thank you!