Ambiguous column name in Ruby on Rails with SQLite database? -


i getting error in rails app:

activerecord::statementinvalid in paymentscontroller#index  sqlite3::sqlexception: ambiguous column name: date: select count(*) "payments" inner join "invoices" on "payments"."invoice_id" = "invoices"."id" "invoices"."user_id" = 1 , (date >= '2013-01-01' , date <= '2013-12-31') 

the problem seems have date field in invoices payments table.

yet still don't know how fix error.

class user < activerecord::base    def number_of_payments_in(year)     payments.where("payments.date >= ? , payments.date <= ?", "#{year}-01-01", "#{year}-12-31").count   end   end 

class payment < activerecord::base    def self.search(year)     if year       where("date >= ? , date <= ?", "#{year}-01-01", "#{year}-12-31")     end   end  end 

can help?

this answer may bit vague it's not clear question class self.search(year) method in, let me know if doesn't , can try , go further.

my guess that, unlike in number_of_payments_in method, in self.search method haven't specified appropriate table in where call.

in number_of_payments_in, specify payments.date, in self.search use date. said have date field in invoices payments table, join call across both tables need every reference date scoped table.

adding appropriate table in front of date in self.search (as have done in number_of_payments_in) may solve problem.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -