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:

product

[i]-id

-published[/i]

product_description

[i]-store_id

-product_id

-name

-description[/i]

The relation I have setup right now in Product is:


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

                'condition'=>'store_id=:store_id',

                'params'=>array(':store_id'=>1)

            ),

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?

Thanks!

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!