Order by in nested includes

Hello there,

I’m encountering a strange issue. I tried to google about it but I may
be using the right wording (I am quite new at RoR).

I’m using some nested eager loading through a scope of one of my models.
I have something like this:

scope :includes_all, lambda {includes(:buggy_relation, 
an_attribute: [:first_attribute, :second_attribute])}

Where :buggy_relation is declared as something like this in the same

has_many :buggy_relation, -> {order(:order_index)}, class_name: 

So, the point is, as long as I do not have an_attribute in my
includes() statement, the SQL request looks correct and I can see the
ORDER BY statement done on my SomeClass.order_index. But, as soon as I
the nested loading with an_attribute: [:first_attribute, :second_attribute], the order of the :buggy_relation is not taken
account anymore. The buggy relation is obviously loaded, but nowhere is
corresponding ORDER BY stated which leads to the order not to be

If you have any hint about this…

– Martin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs