Ambiguous clause in Rails

mysql, ruby-on-rails

Solution

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.

Problem

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? :)

Original source