0

我有几节课:

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

用户和包可以在组中具有成员资格。在我尝试获取属于某个组的用户之前,所有这些似乎都可以。在控制台中,使用组 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

4

0 回答 0