You'll need to configure the primary keys and foreign keys as described in the link already given.
Judging by the example given the relations are:
- Item HasOne Item_Locale
- Item_Locale BelongsTo Item
- Item HasMany Categories
- Category BelongsTo Item
- Category HasOne Category_Locale
- Category_Locale BelongsTo Category
The query for would look something like this:
$items = Model_Item::query()
->related('locale')
->related('categories')
->related('categories.locale')
->where('SellerID', $sellerID)
->get();
I am assuming the locales don't change during runtime, but can't be hardcoded. In which case you need something like the following. Start with setting up the default conditions that are always part of the relations. These need to be added to the definition of the relations in the models, like the following example that would be in Model_Item.
protected static $_has_one = array(
'locale' => array(
'model_to' => 'Model_Item_Locale',
'key_from' => 'ItemId',
'key_to' => 'ItemId',
'conditions' => array(
'join_type' => 'inner',
'where' => array(),
),
),
);
I couldn't add the actual where condition yet as it has to be dynamic and you can't have that in a class property definition. Thus we'll add it the millisecond the class is loaded:
public static function _init()
{
$culture_id = ; // get that from somewhere
static::$_has_one['locale']['where'][] = array('CultureId', '=', $culture_id);
}
This will be added to the join-on part each time, next to the primarykey-foreignkey matching.
The query will return a set of items which will have the locale info inside a property and have an array of categories which all have their own locale property describing them.
foreach ($items as $i)
{
echo $i->locale->Name;
foreach ($i->categories as $c)
{
echo $c->locale->Name;
}
}