This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Many-to-many populates with limit broken #53
Labels
Comments
But why not, SELECT files.* FROM files
INNER JOIN user_has_file ON user_has_file.fileId=files.id
WHERE user_has_file.userId = 1
LIMIT 10; I realize this stuff is complicated, so I may be missing something. @RWOverdijk any idea? |
Failing test: balderdashy/waterline-adapter-tests#83 |
Agreed, it's a serious bug. |
devinivy
added a commit
to devinivy/waterline-sequel
that referenced
this issue
Jul 8, 2015
Proposed change: #54. Makes me sweat! |
Published |
nice 👍 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm experiencing an issue populating with limit. The underlying issue is that when joining, you can of course obtain duplicate records, meaning the limit wont work correctly. The code here does the following...
Say users and files are in a many-to-many relationship, joined on their
id
s. I want to get 10 of user #1
's files. Here's roughly how the sequel looks:I think the issue is that the subquery may return file
id
s for files that belong to other users. Thus, after the join, some records might have duplicate fileid
s (since one row may be for user1
and another row for user2
, who shares the same file). By the time the join is done and is being used, fewer than 10 unique files were found even though the user has more than 10 files.I'm thinking this might be the right idea:
Example rows returned when selecting the file
id
and joineduserId
. Notice files havingid
of1
and2
are duplicated, thus only 8 unique records are returned.The text was updated successfully, but these errors were encountered: