Hi!
I have 3 tables :
Relations in Products are :
public function relations()
{
return array(
'attribute_values' => array(self::HAS_MANY, 'AttributeValue', 'product_id'),
);
}
In AttributeValue :
public function relations()
{
return array(
'attribute' => array(self::BELONGS_TO, 'Attribute', 'attribute_id'),
'product' => array(self::BELONGS_TO, 'Product', 'product_id'),
);
}
In Attribute :
public function relations()
{
return array(
'attribute_values' => array(self::HAS_MANY, 'AttributeValue', 'attribute_id'),
);
}
I execute this code :
$product_id = 1;
$criteria = new CDbCriteria;
$criteria->condition = 't.id='.$product_id;
$criteria->with = array(
'attribute_values.attribute'
);
$attributes=Product::model()->find($criteria);
foreach($attributes as $attribute)
$arr[] = array(
'id'=>// Here I need Product.id
'name'=>// Here I need Attribute.name
'value'=>// And here - AttributeValues.value
);
I need all names from Attribute.name and their values from AttributeValues.value for product.
How can I get Product.id, Attribute.name, AttributeValues.value in this cycle?
Thank you.