I am trying to create an ActiveRecord Object.But I\'m getting this error while creating it.
(0.1ms) ROLLBACK
ActiveRecord::StatementInvalid: PG::InFailedSql
I got that problem. And I found out that it was my query. It mean when I query with association without specifying a table column. ex:
class Holiday < ApplicationRecord
belongs_to :company
end
class Company < ApplicationRecord
has_many :timeoffs
end
In Holiday model I query
company.timeoffs.where("(start_date <= ? and end_date >= ?) and id != ?", begin_date, begin_date, 1)
The error occurs because I didn't specify which table's id
It worked for me after I changed the code to
company.timeoffs.where("(start_date <= ? and end_date >= ?) and time_offs.id != ?", begin_date, begin_date, 1)