SelectAll Overwrites column with same field name in a join
Hello, very odd issue here. I have a table Course with field 'id' and User with field 'id'. When I join these two tables and SelectAll(['Course', 'User']), there's only a single id field, with the value from User. Is this a bug, or am I doing something wrong? (Detailed snippets below).
result:
{
id: 'a0no2ltsuo8chdfaws5l2arqyzhcjp', // <-- this is the actual course ID
instructorId: 'dabkdqgh29j4cfkef3u1b8p63zcjhj',
title: 'Rustic Wooden Ball'
}
result:
{
id: 'dabkdqgh29j4cfkef3u1b8p63zcjhj', // <-- this is now the user id
instructorId: 'dabkdqgh29j4cfkef3u1b8p63zcjhj',
title: 'Rustic Wooden Ball',
name: 'Penny Stroman',
}
Solution:Jump to solution
Kysely is not an ORM. It doesn't magically rename things. You need to provide non-colliding names.
3 Replies
That's just how SQL works
Both returned columns have the same name
id
and the latter overwrites the former
How could anything else possibly happen?Solution
Kysely is not an ORM. It doesn't magically rename things. You need to provide non-colliding names.
@koskimas, gotcha. I was expecting it to auto-rename the field if there was a duplicate in the results, but I get why that would be out of scope for Kysely. Appreciate it.