所以我還沒有找到關於使用activerecord上的條件查找關聯模型的方法的很多文檔,但我已經找到了各種示例。雖然他們似乎都沒有爲我工作。activerecord找到相關模型的條件
user has_one avatar
avatar belongs_to user
Avatar.find(:all, :include => :user, :conditions => {:user => {:login => 'admin'}})
返回長的離譜錯誤
SQLite3::SQLException: no such column: user.login: SELECT "avatars"."id" AS t0_r0, "avatars"."user_id" AS t0_r1, "avatars"."featured" AS t0_r2, "avatars"."avatar_file_name" AS t0_r3, "avatars"."avatar_content_type" AS t0_r4, "avatars"."avatar_file_size" AS t0_r5, "avatars"."created_at" AS t0_r6, "avatars"."updated_at" AS t0_r7, "users"."id" AS t1_r0, "users"."login" AS t1_r1, "users"."email" AS t1_r2, "users"."crypted_password" AS t1_r3, "users"."password_salt" AS t1_r4, "users"."persistence_token" AS t1_r5, "users"."perishable_token" AS t1_r6, "users"."login_count" AS t1_r7, "users"."failed_login_count" AS t1_r8, "users"."last_request_at" AS t1_r9, "users"."current_login_at" AS t1_r10, "users"."last_login_at" AS t1_r11, "users"."current_login_ip" AS t1_r12, "users"."last_login_ip" AS t1_r13, "users"."created_at" AS t1_r14, "users"."updated_at" AS t1_r15 FROM "avatars" LEFT OUTER JOIN "users" ON "users".id = "avatars".user_id WHERE ("user"."login" = 'admin')
我已經嘗試了其他各種模式,包括
:conditions => "user.login == 'admin'"
,但沒有什麼工作。
這是一個軌道2.3.8的應用程序,但也安裝了rails3。所以我有activerecord 3.0.0 & 2.3.8安裝。我認爲這可能是一個問題,但似乎不太可能。的
用戶是否有一個名爲login的字段? – 2010-09-19 18:33:09
記得點贊有用的答案,並檢查最能解答您問題的答案。 – 2010-09-21 20:53:43