Complex relation error - Would it be a bug?

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.

BTW, I could resolve my problem by making each model to point (i.e, to have a relation) to the next one. So, each model ‘knows’ how to get only ‘closer’ related model(s), and so for. This way and I could get the correct data using ‘with()’, something like:

[model]

$models = Composition::find()

        	-&gt;with('compositionToProductOptions.productOption.option')


        	-&gt;all();

[/model]

In other words, I couldnt get options directly in Composition model in this case (so, I think it is a bug) but I could get using eager loading.

Any comments here will still be welcome.