레일 3.2를 사용하고 있습니다. 나는 다음과 같은 설정을 가지고 :레일에있는 모델을 사용하여 쿼리하는 방법
단지 다음과 같이, 액티브 쿼리를 사용하지 않을 경우이 작동class User < ActiveRecord::Base
attr_accessible :is_admin
belongs_to :created_by, :foreign_key => :created_by_id, :class_name => 'User'
end
: 난 정말 어떤 도움을 감사하게 될 것입니다
#rails console
User.first.created_by.is_admin
#=> true
#But I want to query like the following, but it doesn't work
User.where(:created_by => {:is_admin => true})
#ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'created_by.is_admin' in 'where clause'...
#This also doesn't work:
User.joins(:created_by).where(:created_by => {:is_admin => true})
#ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'created_by.is_admin' in 'where clause'
.
'User.includes (: created_by) .where (: created_by => {: is_admin => true})' –
'join '대신'include'도 작동하지 않았습니다 –