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

一个家庭有_许多成员。

这是 with_households 范围定义:

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

电子邮件域长度可能是一个红鲱鱼,但否则我无法重现该错误。为什么在这种情况下 Arel 要做一堆连接?

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 是模棱两可的,这是 AR 的说法:先生,您的 SQL 语句没有意义,因为您正在检查的字段在多个表中找到,我不知道该使用哪个

我猜这个with_households范围是看另一个也有一个电子邮件字段的表。或者,也许你有一个 default_scope 可以做同样的事情。尝试在任何地方指定表名,例如members.emailand 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 回答