You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I'm running into some issues when using a has_many :through association and I was wondering if you could point me in the right direction. I've got a model association like this:
However, when I reference page.blocks in the template, the ordering is not honoring the order set by the default_scope in the BlockAssociation model. Looking through the logs, I'm seeing these queries:
It looks like the block IDs are being retrieved and then a single query to get the blocks is done, but that leads to the blocks being sorted by ID, not by the sort_order field set on the BlockAssociation join table.
The typical query as generated by ActiveRecord is as follows:
Hello! I'm running into some issues when using a
has_many :through
association and I was wondering if you could point me in the right direction. I've got a model association like this:My drop setup for the Page model is also fairly straightforward:
However, when I reference
page.blocks
in the template, the ordering is not honoring the order set by thedefault_scope
in the BlockAssociation model. Looking through the logs, I'm seeing these queries:It looks like the block IDs are being retrieved and then a single query to get the blocks is done, but that leads to the blocks being sorted by ID, not by the
sort_order
field set on the BlockAssociation join table.The typical query as generated by ActiveRecord is as follows:
Unfortunately, all I've been able to figure out so far is to define a method to return the blocks manually:
That, of course, generates another SQL query. Any thoughts on how I could fix this, or maybe point me towards the code? Thanks!
The text was updated successfully, but these errors were encountered: