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

New Eager Loading Bug! #249

Open
danfinlay opened this issue Feb 2, 2015 · 6 comments
Open

New Eager Loading Bug! #249

danfinlay opened this issue Feb 2, 2015 · 6 comments

Comments

@danfinlay
Copy link
Contributor

Hey @ben-ng, it's been a while, but I think I found a bug in eager-loading when using it with pagination!

If I have a bunch of posts and their users, and I want to paginate, I might make a query like this:

geddy.model.Post.all({}, {includes:'Person', limit:100, skip:100, sort:{createdAt:'desc'}}, callback);

which will first fetch the IDs of the relevant posts in an appropriate way, something like:

select post.id, post.createdAt from posts limit 100 skip 100 order by post.createdAt desc;

Which is working fine. The problem is that currently, the follow-up detail request KEEPS the offset, even when querying by ID, which means it skips all the correct results, and returns an empty array:

select post.*, person.* from posts post left outer join people person where ID in (1, 2, 3, 4,...)
ORDER BY post.created_at DESC, OFFSET 100;

This breaks pagination when using eager loaded associations! I think I've boiled it down it should be a quick fix, so I might take a look in there, but I'm sure it would be easier for someone who already has worked with this.

@ben-ng
Copy link

ben-ng commented Feb 2, 2015

Woah! Nice find, I'll take a look after work 😊

@danfinlay
Copy link
Contributor Author

My guess is that this condition should be modified to say:

    if (skip && !query.opts.includes) {

I might have time to check if that works after lunch. Haven't gotten Model's tests running locally somehow. Need to take the time.

@danfinlay
Copy link
Contributor Author

Actually that could be the pre-query, not sure..

@ben-ng
Copy link

ben-ng commented Feb 3, 2015

had an unusually long day at work, going to have to defer this to tomorrow 😞

ping me on twitter if i forget! i have it on my to-do list.

@danfinlay
Copy link
Contributor Author

Yeah no hard feelings, I had a long day too. Hope you beat those tasks back soon!

danfinlay added a commit to danfinlay/model that referenced this issue Feb 6, 2015
Expected it to fail as I've had problems with this type of request
(geddy#249), but was unable to replicate, the test is passing here.
@danfinlay
Copy link
Contributor Author

I wrote a test for what I described, but it's passing. If I can't replicate this soon I'll just close it, maybe something else is going on.

These tests seem to suggest that having an offset of 2 will wrap around the set if there are only two results for the query.

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

No branches or pull requests

2 participants