D
D
dimonfreeman2021-07-09 12:04:29
Yii
dimonfreeman, 2021-07-09 12:04:29

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;
    }


And how to get from the table AttributeName -> name and display, I can not understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dimonfreeman, 2021-07-09
@dimonfreeman

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 question

Ask a Question

731 491 924 answers to any question