I am struggling with the error in object and not sure at all where is the problem.
This is how the models looks like:
class Car < ActiveRecord::Base
has_many :car_colors
has_many :colors, :through => :car_colors
end
class CarColor < ActiveRecord::Base
belongs_to :color
belongs_to :car
end
class Color < ActiveRecord::Base
has_many :car_colors
has_many :cars, :through => :car_colors
end
Here is the query:
@cars = Car.all(:joins => :car_colors, :conditions => { :car_colors => {:color_id => params[:id_number]}}, :order => "cars.created_at DESC")
And the error output:
PG::Error: ERROR: column reference "created_at" is ambiguous
LINE 1: ...d" WHERE "car_colors"."color_id" = 2 AND (created_at...
^
: SELECT "cars".* FROM "cars" INNER JOIN "car_colors" ON "car_colors"."car_id" = "cars"."id" WHERE "car_colors"."color_id" = 2 AND (created_at > '2013-05-03 12:28:36.551058') ORDER BY cars.created_at DESC
The generated SQL query (below the error message) seems to be fine, but what causes the error message?
Thank you in advance.