当我这样做时:
conditions = {:first_name => 'Chris'}
Patient.joins(:user).find(:all, :conditions => conditions)
它生成(并且因为first_name不在Patient表中而失败)
SELECT "patients".* FROM "patients" INNER JOIN "users" ON "users"."id" = "patients"."user_id" WHERE "patients"."first_name" = 'Chris'
我还需要能够查询用户模型的字段并找回Patient对象。这可能吗?
答案 0 :(得分:0)
尝试将条件哈希更改为:
conditions = {'users.first_name' => 'Chris'}
我在Rails 2.3中使用过这种风格,它对我很有用。干杯!
答案 1 :(得分:0)
试试这个:
conditions = ['users.first_name = ?', 'Chris']
Patient.joins(:user).find(:all, :conditions => conditions)