-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
[BUG]: multiple relations in with
operator returns too many rows
#599
Comments
Could you elaborate? What does "explode the amount of rows" mean? What's the expected and actual behavior? |
I'm also getting this issue. I've posted in the discord, but here's my schema: https://gist.github.com/kylewardnz/37104f989807e96555ea856294a2b670 In the database, I have 1 artist, then 2 members linked to the artist via pivot table, and 1 album. This is simplified but what I'm expecting is a structure like so: {
"id": 1,
"name": "Artist 1",
"members": [
{
"id": 1,
"artistId": 1,
"memberId": 1,
"member": {
"id": 1,
"name": "Member 1"
}
},
{
"id": 2,
"artistId": 1,
"memberId": 2,
"member": {
"id": 2,
"name": "Member 2"
}
}
],
"albums": [
{
"id": 1,
"name": "Album 1"
}
]
} With this query here... await db.query.artists.findFirst({
where: (artists, { eq }) => eq(artists.id, 1),
with: {
albums: true,
members: {
with: {
member: true,
}
},
},
}) ...I'm getting a result like so: {
"id": 1,
"name": "Artist 1",
"members": [
{
"id": 1,
"artistId": 1,
"memberId": 1,
"member": {
"id": 1,
"name": "Member 1"
}
},
{
"id": 2,
"artistId": 1,
"memberId": 2,
"member": {
"id": 2,
"name": "Member 2"
}
}
],
"albums": [
{
"id": 1,
"name": "Album 1"
},
{
"id": 1,
"name": "Album 1"
}
]
} If I create a new member and link it to the artist, a third copy of the album with id=1 appears in the albums array. If I remove the members relation from the The inverse also happens. If I have albums 1 & 2 but only member 1, then two copies of member 1 appear in the members array. |
Thanks a lot for the detailed example! |
@twobit @kylewardnz check out |
Thanks @dankochetov, was the |
A quick test on the query I described seems to work properly now, will test a bit more thoroughly later this evening. Thanks @dankochetov! |
it's published as |
Ran into this bug yesterday while fully migrating one of my side projects from Prisma. Just tested the beta, and the query that was giving me problems now works flawlessly. The devil works hard, but the drizzle team works harder 🫡 |
@dankochetov looks like I also needed to upgrade |
I think this change broke another functionality. This example which previously worked is now broken: const result = await drizzle.query.asset.findMany({
with: {
userAssetDrop: {
columns: {},
where: (table) => and(eq(table.userId, input.userId)),
},
talent: {
columns: { id: true, username: true },
},
},
where: (table) => sql`json_array_length(${table.userAssetDrop}) > 0`,
}); I'm getting the error: As soon as I remove the |
fyi, created a new issue: #686 |
What version of
drizzle-orm
are you using?0.26.0
What version of
drizzle-kit
are you using?0.18/0
Describe the Bug
Using the schema below and a query with multiple relations in the
with
operator seems to explode the amount of rows in each relation:Schema:
The text was updated successfully, but these errors were encountered: