2

レールの使用3.2.6。

# 1 letter domain name in email without scope
> Member.where('UPPER(email) LIKE UPPER(?)' , "a@b.com")                                              
  Member Load (0.7ms)  SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a@b.com'))
=> []


# 2 letter domain name in email without scope
>  Member.where('UPPER(email) LIKE UPPER(?)' , "a@bc.com")
  Member Load (0.7ms)  SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a@bc.com'))
=> []

# 1 letter domain name in email with scope
>  Member.with_households.where('UPPER(email) LIKE UPPER(?)' , "a@b.com")
  Member Load (0.7ms)  SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a@b.com'))
=> []

# 2 letter domain name in email with scope
>  Member.with_households.where('UPPER(email) LIKE UPPER(?)' , "a@bs.com")
SQL (0.6ms)  SELECT "members"."id" AS t0_r0, "members"."last_name" AS t0_r1, "members"."first_name" AS t0_r2, "members"."household_id" AS t0_r3, "members"."created_at" AS t0_r4, "members"."updated_at" AS t0_r5, "members"."phone1" AS t0_r6, "members"."phone2" AS t0_r
7, "members"."address1" AS t0_r8, "members"."address2" AS t0_r9, "members"."city" AS t0_r10, "members"."state" AS t0_r11, "members"."zip" AS t0_r12, "members"."notes" AS t0_r13, "members"."active" AS t0_r14, "members"."email" AS t0_r15, "households"."id" AS t1_r0, "ho
useholds"."balance" AS t1_r1, "households"."created_at" AS t1_r2, "households"."updated_at" AS t1_r3, "households"."notes" AS t1_r4, "members_households"."id" AS t2_r0, "members_households"."last_name" AS t2_r1, "members_households"."first_name" AS t2_r2, "members_hou
seholds"."household_id" AS t2_r3, "members_households"."created_at" AS t2_r4, "members_households"."updated_at" AS t2_r5, "members_households"."phone1" AS t2_r6, "members_households"."phone2" AS t2_r7, "members_households"."address1" AS t2_r8, "members_households"."ad
dress2" AS t2_r9, "members_households"."city" AS t2_r10, "members_households"."state" AS t2_r11, "members_households"."zip" AS t2_r12, "members_households"."notes" AS t2_r13, "members_households"."active" AS t2_r14, "members_households"."email" AS t2_r15 FROM "members
" LEFT OUTER JOIN "households" ON "households"."id" = "members"."household_id" LEFT OUTER JOIN "members" "members_households" ON "members_households"."household_id" = "households"."id" WHERE (UPPER(email) LIKE UPPER('a@bs.com'))
ActiveRecord::StatementInvalid: PGError: ERROR:  column reference "email" is ambiguous
LINE 1: ..."."household_id" = "households"."id" WHERE (UPPER(email) LIK...

エラーは次のとおりです。

ActiveRecord::StatementInvalid: PGError: ERROR:  column reference "email" is ambiguous

世帯has_manyメンバー。

with_householdsスコープの定義は次のとおりです。

scope :with_households, :include => [{:household => :members}]

メールドメインの長さは赤いニシンかもしれませんが、それ以外の場合はエラーを再現できませんでした。この場合、なぜアレルはたくさんの結合を行うのですか?

4

3 に答える 3

4

試す

Member.with_households.where('UPPER(members.email) LIKE UPPER(?)' , "a@bs.com")
于 2012-07-16T14:00:10.053 に答える
1

ActiveRecord StatementInvalid is ambiguous is ambiguous is ambiguous is an ARs way: Mrs, your SQL statement does not mean because a field you are found on several tables and I don't know which to use .

with_householdsスコープは、メール フィールドもある別のテーブルを参照していると思います。または、同じことを行う default_scope があるかもしれません。members.emailや など、どこでもテーブル名を指定してみてくださいmanagers.email

于 2012-10-03T09:12:33.393 に答える
0
Member.with_households.where(Member.arel_table[:email].matches("a@bs.com"))
于 2012-07-16T20:57:07.963 に答える