There is no such column - when there is a column

Not sure how this happens, but he says the column does not exist:

SQLite3 :: SQLException: there is no such column: element.kind: SELECT COUNT (*) FROM "answers" INNER JOIN "elements" ON "elements". "id" = "responses". "element_id" WHERE "is responding." "form_id" = 55 AND "element". "kind" = 6

# element.rb
class Element < ActiveRecord::Base
  has_many :answers
end

# answer.rb
class Answer < ActiveRecord::Base
  belongs_to :element
  belongs_to :form
end

class Form < ActiveRecord::Base
  has_many :answers
end

But when I run:

@form.answers.joins(:element).where(:element => {:kind => 6})

I get sql error above. Not sure what is going on. Any thoughts on what I am missing?

Thank!

FYI I run rails 3.2.3 with ruby ​​1.9.3.

+3
source share
1 answer

The table elements, not the elementone generated by the query ( "element"."kind" = 6).

@form.answers.joins(:elements).where(:elements => {:kind => 6})

, element, .joins(:element) .joins(:elements), , , Rails .joins() belongs_to .

@form.answers.joins(:element).where(:elements => {:kind => 6})
+2

All Articles