ruby on rails - Why am I getting error FROM-clause entry for table error? -
i writing app in rails 4.2.1 using jruby 1.7.16.1
i've got user , project models. project has 1 leader , many users through join model:
class project < activerecord::base has_many :users_projects_join has_many :users, :through => :users_projects_join has_many :active_users, -> { where(users_projects_join: {user_status: true}) }, :through => :users_projects_join, :source => :user belongs_to :leader, :class_name => 'user', :foreign_key => :leader_id end
i wanted have :active_users wrote query showed above gives me
error: missing from-clause entry table "users_projects_join" position: 167: select "users".* "users" inner join "users_projects_joins" on "users"."id" = "users_projects_joins"."user_id" "users_projects_joins"."project_id" = 20 , "users_projects_join"."user_status" = 't'
but when execute query strictly in postgres gives me users user_status true. read need add joins(:users_projects_join).where(...) didn't help.
try :
class project < activerecord::base has_many :users_projects_joins has_many :users, :through => :users_projects_joins has_many :active_users, -> { where(users_projects_joins: {user_status: true}) }, :through => :users_projects_joins, :source => :user belongs_to :leader, :class_name => 'user', :foreign_key => :leader_id end
Comments
Post a Comment