Hi guys!
I have a complex relation system where part of it is something like this:
// Tables (04):
// composition(1) <---> (*)composition_to_product_option(1) <---> (1)product_option(*) <---> (1)option
// composition depends on product_option that is a junction table between product and its options;
// composition_to_product_option is another junction table that in this case is between composition (normal) and product_option (junction);
// Relations inside Composition model
public function getCompositionToProductOptions()
{
return $this->hasMany(CompositionToProductOption::className(), ['composition_id' => 'id']);
}
public function getProductOptions()
{
return $this->hasMany(ProductOption::className(), ['id' => 'product_to_option_id']);
->via('compositionToProductOptions');
}
// this relation is being the problem
public function getOptions()
{
return $this->hasMany(Option::className(), ['id' => 'option_id']);
->via('productOptions');
}
When I do a
$composition->productOptions
I get all related models sweetly. Everything works as expected.
BUT running
$composition->options
I run into this:
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: common\models\Composition::product_to_option_id
Since product_to_option_id is a fk field inside the composition_to_product_option table pointing to product_option table, WHY is Yii looking it inside composition model?
Any help here would be very appreciated!
Thanks in advance.