I'm doing a polymorphic join like so :
Object.joins(:customer).includes("jobs.name").merge(@customer.children.scoped).where("name LIKE :name OR job_number LIKE :name", {:name => "JOB" } )
And it's returning as so :
Mysql2::Error: Column 'name' in where clause is ambiguous
Anyone know how to make this un ambigous? :)
It doesn't like the name LIKE
section.
It looks like there is a column named name
in each of the tables. Preface that specific name
with the name of the table you want that value to be from.
This looks like it should be either
.where("jobs.name LIKE :name OR job_number LIKE :name", {:name => "JOB" } )
or
.where("customers.name LIKE :name OR job_number LIKE :name", {:name => "JOB" } )
I've found in general, the best way to resolve these issues is to view the sql generated and determine where the problem is from that. You can find the sql in the logs.
name must be a property (and column) in both jobs and whatever the other object (table) is therefore it needs to be fully qualified.
change
"name like..."
to
"tablename.name like..."
just like you are qualifying
"jobs.name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With