Rails 4: column reference "updated_at" ambiguous with Postgres

I am trying to query a database with a DateTime range for field ' updated_at. The front end sends requests in a JSON array:

["2015-09-01 00:00:00","2015-10-02 23:00:00"]

In the Rails controller, I am parsing two strings in a DateTime using:

start_date = DateTime.parse(params[:date_range_arr][0])
end_date = DateTime.parse(params[:date_range_arr][1])

#...
@events = @events.where('updated_at BETWEEN ? AND ?,
       start_date, end_date
)

Queries show:

WHERE (updated_at BETWEEN '2015-09-01 00:00:00.000000' AND '2015-10-02 23:00:00.000000')

And errors:

ActionView::Template::Error (PG::AmbiguousColumn: ERROR:  column reference "updated_at" is ambiguous
LINE 1: ...texts"."id" = "events"."context_id" WHERE (updated_at...
+4
source share
1 answer

Do you have a random default area with a connection or inclusion in the Event model or in the code above what is included in the original question?

In any case, you just need to be more specific with your request as follows:

#...
@events = @events.where('events.updated_at BETWEEN ? AND ?,
   start_date, end_date
)
+7
source

Source: https://habr.com/ru/post/1610024/


All Articles