Rails ActiveRecord: PG::Error: ERROR: column reference "created_at" is ambiguous Rails ActiveRecord: PG::Error: ERROR: column reference "created_at" is ambiguous ruby ruby

Rails ActiveRecord: PG::Error: ERROR: column reference "created_at" is ambiguous


There likely is a created_at field in your car_colors table. created_at should probably be cars.created_at to remove the ambiguity.


Define a scope like this:

scope :scope_age, -> { order(created_at: :desc) }

rather than:

scope :scope_age, -> { order("created_at DESC") }

It removes the ambiguity by using the property of the model in which the scope is defined in.


Don't remove your timestamps from the join model, they aren't the problem - the problem is that something is adding a condition to your query:

AND (created_at > '2013-05-03 12:28:36.551058')

Since the date is one month ago, search your code for one.month.ago and see if it appears in any scopes, probably in your cars or car_colors models. Check the scopes manually if nothing turns up through the search.

Removing the timestamps will make your query work, but it's not the right thing to do.