Answer the question
In order to leave comments, you need to log in
How to get attribute name from table C?
There is a table of products, a table of attribute names, and a table with product + attribute value + attribute id.
Prompt how to receive attribute names with the minimum expenses.
In the product model
public function getAttributeLists()
{
return $this->hasMany(AttributeList::className(), ['product_id' => 'id']);
}
public function getAttributeValue(){
return $this->attributeLists->attr_value;
}
Answer the question
In order to leave comments, you need to log in
public function getAttr()
{
return $this->hasOne(AttributeName::className(), ['id' => 'attr_id']);
}
and in the model call $product->attributeLists->attr->name;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question