Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Need Help With Conditional Relational Active Record

$
0
0
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
-id
-published


product_description
-store_id
-product_id
-name
-description


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!

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>