column reference "name" is ambiguous
See original GitHub issueHi,
I’m running into an issue with a combination of query
and where
clauses on a model. I’m running on PostgreSQL database.
The following code is dynamically built depending on the API request:
Brand.query((qb) => {
qb.innerJoin('partners as p', function() {
this.on('brands.partner_id', '=', 'p.id')
});
qb.where('p.name', 'ILIKE', '%partnername%');
})
.where('name','=','brandname')
.fetch();
results in:
error: select "brands".* from "brands" inner join "partners" as "p" on "brands"."partner_id" = "p"."id" where "p"."name" ILIKE $1 and "name" ILIKE $2 order by "brands"."id" ASC limit $3 - column reference "name" is ambiguous
Again, the where clause is built dynamically from the API request. Is there any way to either prefix the where property with the tablename or to add an alias for the Brand model’s properties?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
SQL column reference "id" is ambiguous - Stack Overflow
This issue actually happens when there is same column name in both tables. where <tableName.columnName> = <value> can solve this issue. – Shah...
Read more >How to Solve the “Ambiguous Name Column” Error in SQL
One of the simplest ways to solve an “ambiguous name column” error — without changing column name — is to give the tables...
Read more >U122: Column reference is ambiguous - pganalyze
This error occurs when the referenced column can't be resolved unambiguously. This may occur when you have two tables that have columns with...
Read more >Column is ambiguous SQL Error (Community) - Looker Support
You may see an error that says something like Column 'id' in field list is ambiguous . This error means that there is...
Read more >What does the SQL 'ambiguous column name' error mean?
“Ambiguous column name” means that you are referencing an attribute or attributes that belong to more than one of the tables you are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have been using plugin that creates a static method
field
.Then it can be used like
Model.field('someFieldName')
. Eg.Closing this since there are several proposed solutions and the user never responded back.