Skip to content

Can't eager load self_and_ancestors association in Rails 4.1 #137

Open
@jturkel

Description

@jturkel

Not sure if this is the same issues as in #70 but eager loading the self_and_ancestors association in Rails 4.1 generates invalid SQL.

Consider the following model:

class Category < ActiveRecord::Base
  acts_as_tree
end

Attempting to run Category.includes(:self_and_ancestors).to_a generates the following invalid SQL:

SELECT "categories".* 
FROM "categories"  
WHERE "categories"."id" IN (3, 2, 1)  
ORDER BY "category_hierarchies".generations asc

This worked fine in Rails 4.0. A full test case can be found in https://gist.github.com/jturkel/82df7f9e4ccf96df14a5.

It looks like the problematic order on the self_and_ancestors relation is unnecessary in Rails 4.1 since the ActiveRecord::Associations::Preloader::ThroughAssociation preserves the order of the source association.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions