Relations behaving differently

I need to get a deeply nested collection of models on another one (companies->bidCompanies->rfbs->pricings); bidCompanies is a joint model between companies and rfbs (many to many), and pricings has a one to many relation with rfbs and since we have a collection of rfbs, we have to get as many pricings as rfbs.

Relations method in one of my models:




            'bidCompanies' => array(self::HAS_MANY, 'BidCompanies', 'id_companies'), // not doing too much in this case

            'rfbs' => [

                self::MANY_MANY,

                'BidRfbs',

                "bidCompanies(id_companies, id_bidRfbs)",

            ],

            'pricings' => [

                self::HAS_MANY,

                'Bids',

                'id_bids',

                'through' => 'rfbs',

            ],

            // dummy relation to simplify the example: rfbs2 works with 'through' => 'bidCompanies' too

            'bidCompanies2' => [

                self::HAS_MANY,

                'BidCompanies',

                "id_companies",

            ],

            'rfbs2' => [

                self::HAS_MANY,

                'BidRfbs',

                "id_bidRfbs",

                'through' => 'bidCompanies2',

            ],

            'pricings2' => [

                self::HAS_MANY,

                'Bids',

                'id_bids',

                'through' => 'rfbs2',

            ],



[color="#9ACD32"]pricings2[/color] works, giving me a collection based on others, like [color="#9ACD32"]rfbs2[/color] and [color="#9ACD32"]bidCompanies2[/color]. But [color="#FF0000"]pricings[/color], even though [color="#FF0000"]rfbs[/color] is an array identical to [color="#9ACD32"]rfbs2[/color], doesn’t work. If I change [color="#FF0000"]pricings[/color] from


'through' => 'rfbs'

to


'through' => 'rfbs2'

it works as expected.

To summarize:

[color="#FF0000"]company->rfbs->pricings[/color] (n-m,n-1): [color="#FF0000"]pricings[/color] is null, even though [color="#FF0000"]rfbs[/color] is correctly populated (actually it is identical to [color="#9ACD32"]rfbs2[/color]).

[color="#9ACD32"]company->bidCompanies2->rfbs2->pricings2[/color] (1-n,n-1,n-1): all collections are correctly populated.

Why does it work when replacing the MANY_MANY relation with two HAS_MANY even though the common intermediate "steps" ([color="#FF0000"]rfbs[/color] and [color="#9ACD32"]rfbs2[/color] collections) are identical?

Thank you in advance.

Nobody?