因此,與這種關聯的複雜情況是我使用的命名空間,解決方案似乎相對簡單 - 主要是在協會的accounts_account
一側添加foreign_key:
選項。
我用這個源爲起點:http://joeswann.co.nz/rails-4-has_many-polymorphic-relationships,與Article
適於每個用戶類型(Users::SuperAdminUser
,Users::AdminUser
,和Users::StandardUser
)Tag
適於Accounts::Account
和TagTarget
適於Accounts::AccountMembership
的。然後,我在class_name:
和foreign_key:
選項中添加了需要調整類名稱空間的選項。
此外,我向Accounts::Account
類添加了一個實例方法users_account_members
以啓用所有用戶類型的帳戶成員的檢索。我想我想知道,如果我不能在沒有添加此方法的情況下檢索所有用戶類型的所有帳戶成員,那麼這種多態關係的點/好處是。看起來我可以通過Accounts::Account
與每個用戶類型之間的單獨has_many
關係實現同樣的功能。
修訂後的課程如下所示(沒有更改遷移):
module Accounts
class Account < ApplicationRecord
has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', dependent: :destroy, foreign_key: :accounts_account_id
has_many :users_super_admin_users, through: :accounts_account_memberships, source: :users_account_member, source_type: "Users::SuperAdminUser"
has_many :users_admin_users, through: :accounts_account_memberships, source: :users_account_member, source_type: "Users::AdminUser"
has_many :users_standard_users, through: :accounts_account_memberships, source: :users_account_member, source_type: "Users::StandardUser"
def users_account_members
self.users_super_admin_users + self.users_admin_users + self.users_standard_users
end
end
end
module Accounts
class AccountMembership < ApplicationRecord
belongs_to :accounts_account, class_name: 'Accounts::Account'
belongs_to :users_account_member, polymorphic: true
end
end
module Users
class SuperAdminUser < ApplicationRecord
has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy
has_many :accounts_accounts, through: :accounts_account_memberships, as: :users_account_member
end
end
module Users
class AdminUser < ApplicationRecord
has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy
has_many :accounts_accounts, through: :accounts_account_memberships, as: :users_account_member
end
end
module Users
class StandardUser < ApplicationRecord
has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy
has_many :accounts_accounts, through: :accounts_account_memberships, as: :users_account_member
end
end
有了這些變化,在Rails的控制檯響應是現在(注:數據庫種子文件中出現以下控制檯輸出) :
2.4.0 :001 > Accounts::Account.first.users_account_owner
Accounts::Account Load (0.8ms) SELECT "accounts_accounts".* FROM "accounts_accounts" ORDER BY "accounts_accounts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Users::SuperAdminUser Load (0.5ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" WHERE "users_super_admin_users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
=> #<Users::SuperAdminUser id: 1, email: "[email protected]", first_name: "Gregory", last_name: "Arnold", username: "garnold0", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">
2.4.0 :002 > Users::SuperAdminUser.first.accounts_owned_accounts
Users::SuperAdminUser Load (0.4ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" ORDER BY "users_super_admin_users"."id" ASC LIMIT $1 [["LIMIT", 1]]
Accounts::Account Load (0.4ms) SELECT "accounts_accounts".* FROM "accounts_accounts" WHERE "accounts_accounts"."users_account_owner_id" = $1 [["users_account_owner_id", 1]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 1, name: "Ooba", users_account_owner_id: 1, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :003 > Accounts::Account.first.users_super_admin_users
Accounts::Account Load (0.6ms) SELECT "accounts_accounts".* FROM "accounts_accounts" ORDER BY "accounts_accounts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Users::SuperAdminUser Load (0.8ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" INNER JOIN "accounts_account_memberships" ON "users_super_admin_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::SuperAdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Users::SuperAdminUser id: 1, email: "[email protected]", first_name: "Gregory", last_name: "Arnold", username: "garnold0", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::SuperAdminUser id: 6, email: "[email protected]", first_name: "Nicole", last_name: "Cruz", username: "ncruz5", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :004 > Accounts::Account.first.users_admin_users
Accounts::Account Load (0.6ms) SELECT "accounts_accounts".* FROM "accounts_accounts" ORDER BY "accounts_accounts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Users::AdminUser Load (0.8ms) SELECT "users_admin_users".* FROM "users_admin_users" INNER JOIN "accounts_account_memberships" ON "users_admin_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::AdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Users::AdminUser id: 4, email: "[email protected]", first_name: "Henry", last_name: "Lane", username: "hlaned", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::AdminUser id: 9, email: "[email protected]", first_name: "Raymond", last_name: "Harvey", username: "rharveyi", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :005 > Accounts::Account.first.users_standard_users
Accounts::Account Load (0.4ms) SELECT "accounts_accounts".* FROM "accounts_accounts" ORDER BY "accounts_accounts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Users::StandardUser Load (0.7ms) SELECT "users_standard_users".* FROM "users_standard_users" INNER JOIN "accounts_account_memberships" ON "users_standard_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::StandardUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Users::StandardUser id: 2, email: "[email protected]", first_name: "Gary", last_name: "Hamilton", username: "ghamiltonl", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::StandardUser id: 7, email: "[email protected]", first_name: "Jonathan", last_name: "Kelly", username: "jkellyq", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :006 > Accounts::Account.first.users_account_members
Accounts::Account Load (0.6ms) SELECT "accounts_accounts".* FROM "accounts_accounts" ORDER BY "accounts_accounts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Users::SuperAdminUser Load (0.7ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" INNER JOIN "accounts_account_memberships" ON "users_super_admin_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::SuperAdminUser"]]
Users::AdminUser Load (0.6ms) SELECT "users_admin_users".* FROM "users_admin_users" INNER JOIN "accounts_account_memberships" ON "users_admin_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::AdminUser"]]
Users::StandardUser Load (0.7ms) SELECT "users_standard_users".* FROM "users_standard_users" INNER JOIN "accounts_account_memberships" ON "users_standard_users"."id" = "accounts_account_memberships"."users_account_member_id" WHERE "accounts_account_memberships"."accounts_account_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["accounts_account_id", 1], ["users_account_member_type", "Users::StandardUser"]]
=> [#<Users::SuperAdminUser id: 1, email: "[email protected]", first_name: "Gregory", last_name: "Arnold", username: "garnold0", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::SuperAdminUser id: 6, email: "[email protected]", first_name: "Nicole", last_name: "Cruz", username: "ncruz5", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::AdminUser id: 4, email: "[email protected]", first_name: "Henry", last_name: "Lane", username: "hlaned", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::AdminUser id: 9, email: "[email protected]", first_name: "Raymond", last_name: "Harvey", username: "rharveyi", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::StandardUser id: 2, email: "[email protected]", first_name: "Gary", last_name: "Hamilton", username: "ghamiltonl", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">, #<Users::StandardUser id: 7, email: "[email protected]", first_name: "Jonathan", last_name: "Kelly", username: "jkellyq", created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]
2.4.0 :007 > Users::SuperAdminUser.first.accounts_accounts
Users::SuperAdminUser Load (0.6ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" ORDER BY "users_super_admin_users"."id" ASC LIMIT $1 [["LIMIT", 1]]
Accounts::Account Load (0.8ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 1], ["users_account_member_type", "Users::SuperAdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 1, name: "Ooba", users_account_owner_id: 1, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :008 > Users::SuperAdminUser.second.accounts_accounts
Users::SuperAdminUser Load (0.4ms) SELECT "users_super_admin_users".* FROM "users_super_admin_users" ORDER BY "users_super_admin_users"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1], ["OFFSET", 1]]
Accounts::Account Load (0.7ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 2], ["users_account_member_type", "Users::SuperAdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 4, name: "Brainsphere", users_account_owner_id: 4, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :009 > Users::AdminUser.first.accounts_accounts
Users::AdminUser Load (0.4ms) SELECT "users_admin_users".* FROM "users_admin_users" ORDER BY "users_admin_users"."id" ASC LIMIT $1 [["LIMIT", 1]]
Accounts::Account Load (0.6ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 1], ["users_account_member_type", "Users::AdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 2, name: "Avamba", users_account_owner_id: 2, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :010 > Users::AdminUser.second.accounts_accounts
Users::AdminUser Load (0.5ms) SELECT "users_admin_users".* FROM "users_admin_users" ORDER BY "users_admin_users"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1], ["OFFSET", 1]]
Accounts::Account Load (0.7ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 2], ["users_account_member_type", "Users::AdminUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 5, name: "Wordtune", users_account_owner_id: 5, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :011 > Users::StandardUser.first.accounts_accounts
Users::StandardUser Load (0.5ms) SELECT "users_standard_users".* FROM "users_standard_users" ORDER BY "users_standard_users"."id" ASC LIMIT $1 [["LIMIT", 1]]
Accounts::Account Load (0.7ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 1], ["users_account_member_type", "Users::StandardUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 3, name: "Linktype", users_account_owner_id: 3, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
2.4.0 :012 > Users::StandardUser.second.accounts_accounts
Users::StandardUser Load (0.4ms) SELECT "users_standard_users".* FROM "users_standard_users" ORDER BY "users_standard_users"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1], ["OFFSET", 1]]
Accounts::Account Load (0.6ms) SELECT "accounts_accounts".* FROM "accounts_accounts" INNER JOIN "accounts_account_memberships" ON "accounts_accounts"."id" = "accounts_account_memberships"."accounts_account_id" WHERE "accounts_account_memberships"."users_account_member_id" = $1 AND "accounts_account_memberships"."users_account_member_type" = $2 [["users_account_member_id", 2], ["users_account_member_type", "Users::StandardUser"]]
=> #<ActiveRecord::Associations::CollectionProxy [#<Accounts::Account id: 1, name: "Ooba", users_account_owner_id: 1, created_at: "2017-02-11 21:01:57", updated_at: "2017-02-11 21:01:57">]>
分貝/ seeds.rb
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Gregory', last_name: 'Arnold', username: 'garnold0')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Lisa', last_name: 'Sanders', username: 'lsanders1')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Scott', last_name: 'Sanders', username: 'ssanders2')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Anthony', last_name: 'Roberts', username: 'aroberts3')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Paula', last_name: 'Robinson', username: 'probinson4')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Nicole', last_name: 'Cruz', username: 'ncruz5')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'George', last_name: 'Andrews', username: 'gandrews6')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Nicole', last_name: 'Wilson', username: 'nwilson7')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Anne', last_name: 'Edwards', username: 'aedwards8')
Users::SuperAdminUser.create(email: '[email protected]', first_name: 'Ronald', last_name: 'Davis', username: 'rdavis9')
Users::AdminUser.create(email: '[email protected]', first_name: 'Lisa', last_name: 'Hawkins', username: 'lhawkinsa')
Users::AdminUser.create(email: '[email protected]', first_name: 'Helen', last_name: 'Taylor', username: 'htaylorb')
Users::AdminUser.create(email: '[email protected]', first_name: 'Gregory', last_name: 'Taylor', username: 'gtaylorc')
Users::AdminUser.create(email: '[email protected]', first_name: 'Henry', last_name: 'Lane', username: 'hlaned')
Users::AdminUser.create(email: '[email protected]', first_name: 'Harry', last_name: 'Phillips', username: 'hphillipse')
Users::AdminUser.create(email: '[email protected]', first_name: 'Jeffrey', last_name: 'Gonzales', username: 'jgonzalesf')
Users::AdminUser.create(email: '[email protected]', first_name: 'Lori', last_name: 'James', username: 'ljamesg')
Users::AdminUser.create(email: '[email protected]', first_name: 'Roger', last_name: 'Hill', username: 'rhillh')
Users::AdminUser.create(email: '[email protected]', first_name: 'Raymond', last_name: 'Harvey', username: 'rharveyi')
Users::AdminUser.create(email: '[email protected]', first_name: 'Stephen', last_name: 'Perry', username: 'sperryj')
Users::StandardUser.create(email: '[email protected]', first_name: 'Michelle', last_name: 'Black', username: 'mblackk')
Users::StandardUser.create(email: '[email protected]', first_name: 'Gary', last_name: 'Hamilton', username: 'ghamiltonl')
Users::StandardUser.create(email: '[email protected]', first_name: 'Chris', last_name: 'Gray', username: 'cgraym')
Users::StandardUser.create(email: '[email protected]', first_name: 'Jacqueline', last_name: 'Bradley', username: 'jbradleyn')
Users::StandardUser.create(email: '[email protected]', first_name: 'Joseph', last_name: 'Payne', username: 'jpayneo')
Users::StandardUser.create(email: '[email protected]', first_name: 'Debra', last_name: 'Rodriguez', username: 'drodriguezp')
Users::StandardUser.create(email: '[email protected]', first_name: 'Jonathan', last_name: 'Kelly', username: 'jkellyq')
Users::StandardUser.create(email: '[email protected]', first_name: 'Cheryl', last_name: 'Reynolds', username: 'creynoldsr')
Users::StandardUser.create(email: '[email protected]', first_name: 'Kathleen', last_name: 'Barnes', username: 'kbarness')
Users::StandardUser.create(email: '[email protected]', first_name: 'Annie', last_name: 'Hansen', username: 'ahansent')
Accounts::Account.create(name: 'Ooba', users_account_owner_id: 1)
Accounts::Account.create(name: 'Avamba', users_account_owner_id: 2)
Accounts::Account.create(name: 'Linktype', users_account_owner_id: 3)
Accounts::Account.create(name: 'Brainsphere', users_account_owner_id: 4)
Accounts::Account.create(name: 'Wordtune', users_account_owner_id: 5)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 1)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::AdminUser', users_account_member_id: 1)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::StandardUser', users_account_member_id: 1)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 2)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::AdminUser', users_account_member_id: 2)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::StandardUser', users_account_member_id: 2)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 3)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::AdminUser', users_account_member_id: 3)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::StandardUser', users_account_member_id: 3)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 4)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::AdminUser', users_account_member_id: 4)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::StandardUser', users_account_member_id: 4)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 5)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::AdminUser', users_account_member_id: 5)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::StandardUser', users_account_member_id: 5)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 6)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::AdminUser', users_account_member_id: 6)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::StandardUser', users_account_member_id: 6)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 7)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::AdminUser', users_account_member_id: 7)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::StandardUser', users_account_member_id: 7)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 8)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::AdminUser', users_account_member_id: 8)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::StandardUser', users_account_member_id: 8)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 9)
Accounts::AccountMembership.create(accounts_account_id: 1, users_account_member_type: 'Users::AdminUser', users_account_member_id: 9)
Accounts::AccountMembership.create(accounts_account_id: 2, users_account_member_type: 'Users::StandardUser', users_account_member_id: 9)
Accounts::AccountMembership.create(accounts_account_id: 3, users_account_member_type: 'Users::SuperAdminUser', users_account_member_id: 10)
Accounts::AccountMembership.create(accounts_account_id: 4, users_account_member_type: 'Users::AdminUser', users_account_member_id: 10)
Accounts::AccountMembership.create(accounts_account_id: 5, users_account_member_type: 'Users::StandardUser', users_account_member_id: 10)
感謝您的快速響應。我添加了您建議的列,並取得了一些進展,即我不再收到有關accounts_account_type的錯誤,但仍未返回記錄。我也沒有看到accounts_account_type是如何被需要的,因爲關聯的accounts_account方面不是多態的。我懷疑我的問題與命名空間內的模型有關,而且似乎確實存在問題。看到我的解決方案,現在似乎按預期工作。 – eggroll