Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zero length paths in eagerload #1666

Open
amitsuryavanshi opened this issue Jan 4, 2022 · 0 comments
Open

Allow zero length paths in eagerload #1666

amitsuryavanshi opened this issue Jan 4, 2022 · 0 comments
Labels

Comments

@amitsuryavanshi
Copy link
Member

Given,

class Person
        has_many :out, :knows, model_class: 'Person', type: nil
        has_many :in, :posts, type: :posts
end

class Post
      has_one :out, :owner, origin: :posts, model_class: 'Person'
end

Currently we only allow fixed length or infinite length paths in eager load like Person.where(id: [1,5,6]).with_association('knows*') or Person.where(id: [1,5,6]).with_association('knows*4'). If we want to eager load post on persons and the persons that they know, we have to do Person.where(id: [1,5,6]).with_association(['posts', 'knows*.posts']). This results in tow optional matches for person's posts and persons's know's posts. To avoid this we can have Person.where(id: [1,5,6]).with_association('knows*0...posts'), which will result in only one optional match for posts, hence shorter and faster query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant