Closed lexdevelop closed 9 months ago
Hi, you need to prefix the columns coming from the user_details
table in your SQL:
"SELECT u.*, ud.id as "user_detail.id", ud.first_name as "user_detail.first_name", ... FROM users as u INNER JOIN users_details as ud ON users_details.id = users.user_detail_id WHERE users.email = @email",
You need to do this because when you do select *
from multiple tables, the database puts all columns in a single namespace with no prefixes. For Scany to be able to map nested structs (your Details
struct is nested into the User
struct), it needs all columns to be uniquely named, which is achieved by prefixing nested structs.
I hope this helps; feel free to reopen if you have more questions.
Hello, I'm trying to populate struct which contain one to one relation, but I'm getting the following error
duplicate columns: scany: rows contain a duplicate column 'id'"
Any help on what I'm doing wrong will be great.Here are my Entities
And here is the repository function where I'm doing query
My database postgress database structure is following