You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT t.*, SUM(p.amount) paid FROM transactions t LEFT JOIN payments p ON t.id = p.transaction_id WHERE (id IN (4,8,6)) GROUP BY t.id
Note the "WHARE" clause. This query will fail if both "transactions" and "payments" had the same column name "id" for their primary key.
The workaround is to rename one of the column names, for example change "id" in "payments" to be "payment_id". But this is limiting and non conventional.
The optimal solution is to use the fully qualified name of the primary key in the where clause, which should generate this sql instead:
SELECT t.*, SUM(p.amount) paid FROM transactions t LEFT JOIN payments p ON t.id = p.transaction_id WHERE (transactions.id IN (4,8,6)) GROUP BY t.id
The text was updated successfully, but these errors were encountered:
This issue will be automatically closed because it is marked as GORM V1 issue, we have released the public testing GORM V2 release and its documents https://v2.gorm.io/docs/ already, the testing release has been used in some production services for a while, and going to release the final version in following weeks, we are still actively collecting feedback before it, please open a new issue for any suggestion or problem, thank you
There's an issue that can make the primary key column ambiguous when using Prelaod.
Here's an exaple of "Has Many" where each "transaction" has many "payments"
This would generate the following query:
SELECT t.*, SUM(p.amount) paid FROM transactions t LEFT JOIN payments p ON t.id = p.transaction_id WHERE (
idIN (4,8,6)) GROUP BY t.id
Note the "WHARE" clause. This query will fail if both "transactions" and "payments" had the same column name "id" for their primary key.
The workaround is to rename one of the column names, for example change "id" in "payments" to be "payment_id". But this is limiting and non conventional.
The optimal solution is to use the fully qualified name of the primary key in the where clause, which should generate this sql instead:
SELECT t.*, SUM(p.amount) paid FROM transactions t LEFT JOIN payments p ON t.id = p.transaction_id WHERE (
transactions.
idIN (4,8,6)) GROUP BY t.id
The text was updated successfully, but these errors were encountered: