有很多:通过一个多态关联而不是带有Squeel 1.1.1的别名类型列

时间:2013-10-29 14:02:07

标签: ruby-on-rails associations has-many-through polymorphism squeel

我有几节课:

class Membership < ActiveRecord::Base
  belongs_to :group
  belongs_to :member, polymorphic: true
end

class User < ActiveRecord::Base
  has_many :memberships, as: :member, dependent: :destroy
  has_many :groups, through: :memberships
end

class Package < ActiveRecord::Base
  has_many :memberships, as: :member, dependent: :destroy
  has_many :groups, through: :memberships
end

class Group < ActiveRecord::Base
  has_many :memberships, dependent: :destroy, inverse_of: :member
  has_many :packages, through: :memberships, source: :member, source_type: 'Package'
  has_many :users, through: :memberships, source: :member, source_type: 'User'
end

用户和包可以拥有群组成员资格。在我尝试获取属于组的用户之前,所有这些似乎都可以。在控制台中,使用Group g的实例:

[5] pry(main)> g.users
  User Load (3.3ms)  SELECT "USERS".* FROM "USERS" INNER JOIN "MEMBERSHIPS" ON 
"USERS"."ID" = "MEMBERSHIPS"."MEMBER_ID" WHERE "MEMBERSHIPS"."GROUP_ID" = :a1 AND
"USERS"."MEMBER_TYPE" = 'User'  [["group_id", 10000]]
OCIError: ORA-00904: "USERS"."MEMBER_TYPE": invalid identifier: 
  SELECT "USERS".* 
  FROM "USERS" 
    INNER JOIN "MEMBERSHIPS" ON "USERS"."ID" = "MEMBERSHIPS"."MEMBER_ID" 
  WHERE "MEMBERSHIPS"."GROUP_ID" = :a1 
    AND "USERS"."MEMBER_TYPE" = 'User'

很容易看到错误 - Users表没有Member_Type列,它驻留在Membership表中。

为什么列没有正确别名?其他人有这个问题吗?

更新

这是Squeel的问题 - 将其从我的Gemfile中删除,并且关联行为正常。

记录了一个问题 - https://github.com/ernie/squeel/issues/288

0 个答案:

没有答案