1

我的類和遷移如下。不知道我做錯了什麼,我是否設置了錯誤的關聯,或者我沒有使用正確的屬性/方法來返回我期待的記錄。例如,如何獲得account的所有成員(super_admin_usersadmin_usersstandard_users)的列表?在Rails的控制檯,如果我嘗試Accounts::Account.first.users_account_members,我得到如下:Rails has_many通過多態命名空間模型

2.4.0 :003 > 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]] 
NoMethodError: undefined method `users_account_members' for #<Accounts::Account:0x007fcb10cce7b8> 

如果我嘗試Accounts::Account.first.users_super_admin_users,我得到如下:

2.4.0 :004 > 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]] 
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column accounts_account_memberships.accounts_account_type does not exist 

,其中,通過尋找accounts_account_memberships.accounts_account_type,它似乎就好像該協會的accounts_account一側是多態的,只有用戶方是。

另外,怎麼樣,相反的,我會得到所有accounts特定super_admin_user(或admin_user,或standard_user)的列表中的一員?

這裏是我的班,協會及其遷移:

應用程序/模型/帳號/ account.rb

module Accounts 
    class Account < ActiveRecord::Base 

    self.table_name = 'accounts_accounts' 

    belongs_to :users_account_owner, class_name: 'Users::SuperAdminUser', inverse_of: :accounts_owned_accounts 
    accepts_nested_attributes_for :users_account_owner 

    has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :accounts_account, dependent: :destroy 
    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' 

    end 
end 

應用程序/模型/用戶/ super_admin_user.rb

module Users 
    class SuperAdminUser < ApplicationRecord 

    self.table_name = 'users_super_admin_users' 

    has_many :accounts_owned_accounts, class_name: 'Accounts::Account', inverse_of: :users_account_owner, foreign_key: :users_account_owner_id 

    has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy 
    has_many :accounts_accounts, through: :accounts_account_memberships, source: 'Accounts::Account' 

    end 
end 

app/models/users/admin_user.rb

module Users 
    class AdminUser < ApplicationRecord 

    self.table_name = 'users_admin_users' 

    has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy 
    has_many :accounts_accounts, through: :accounts_account_memberships, source: 'Accounts::Account' 

    end 
end 

應用程序/模型/用戶/ standard_user.rb

module Users 
    class StandardUser < ApplicationRecord 

    self.table_name = 'users_standard_users' 

    has_many :accounts_account_memberships, class_name: 'Accounts::AccountMembership', as: :users_account_member, dependent: :destroy 
    has_many :accounts_accounts, through: :accounts_account_memberships, source: 'Accounts::Account' 

    end 
end 

應用程序/模型/帳號/ account_membership.rb

module Accounts 
    class AccountMembership < ActiveRecord::Base 

    self.table_name = 'accounts_account_memberships' 

    belongs_to :accounts_account, class_name: 'Accounts::Account', inverse_of: :accounts_account_memberships 
    belongs_to :users_account_member, polymorphic: true 

    end 
end 

DB /遷移/ 20170203001000_create_users_super_admin_user .rb

class CreateUsersSuperAdminUser < ActiveRecord::Migration[5.0] 
    def change 
    create_table :users_super_admin_users do |t| 

     t.string :email, index: { unique: true } 
     t.string :first_name 
     t.string :last_name 
     t.string :username, index: { unique: true } 

     t.timestamps null: false 

    end 
    end 
end 

分貝/遷移/ 20170203001100_create_users_admin_user.rb

class CreateUsersAdminUser < ActiveRecord::Migration[5.0] 
    def change 
    create_table :users_admin_users do |t| 

     t.string :email, index: { unique: true } 
     t.string :first_name 
     t.string :last_name 
     t.string :username, index: { unique: true } 

     t.timestamps null: false 

    end 
    end 
end 

分貝/遷移/ 20170203001200_create_users_standard_user.rb

class CreateUsersStandardUser < ActiveRecord::Migration[5.0] 
    def change 
    create_table :users_standard_users do |t| 

     t.string :email, index: { unique: true } 
     t.string :first_name 
     t.string :last_name 
     t.string :username, index: { unique: true } 

     t.timestamps null: false 

    end 
    end 
end 

分貝/遷移/ 20170204001000_create_accounts_account。RB

class CreateAccountsAccount < ActiveRecord::Migration[5.0] 
    def change 
    create_table :accounts_accounts do |t| 

     t.string :name, index: { unique: true } 

     t.references :users_account_owner, index: true, foreign_key: { to_table: :users_super_admin_users } 

     t.timestamps null: false 

    end 
    end 
end 

DB /遷移/ 20170204001100_create_accounts_account_membership.rb

class CreateAccountsAccountMembership < ActiveRecord::Migration[5.0] 
    def change 
    create_table :accounts_account_memberships do |t| 

     t.references :accounts_account, index: { name: 'index_accts_acct_mbrships_on_accts_acct_id' } 
     t.references :users_account_member, polymorphic: true, index: { name: 'index_accts_acct_mbrships_on_users_acct_member_type_and_id' } 

     t.timestamps null: false 

    end 
    end 
end 

回答

0

要與你在AccountMembership模型來聲明一個類型列這樣的多態關聯工作。

像這樣:

class AddAccountsAccountTypeToAccountsAccountMemberships < ActiveRecord::Migration[5.0] 
    def change 
    add_column :accounts_account_memberships, :accounts_account_type, :string 
    end 
end 

如果我理解正確的話,讓你不得不使用Accounts::Account.first.accounts_account_memberships代替Accounts::Account.first.users_account_members

而且讓所有accounts特定standard_user的列表中的所有成員名單你應該打電話像Users::StandardUser.first.accounts_accounts

+0

感謝您的快速響應。我添加了您建議的列,並取得了一些進展,即我不再收到有關accounts_account_type的錯誤,但仍未返回記錄。我也沒有看到accounts_account_type是如何被需要的,因爲關聯的accounts_account方面不是多態的。我懷疑我的問題與命名空間內的模型有關,而且似乎確實存在問題。看到我的解決方案,現在似乎按預期工作。 – eggroll

0

因此,與這種關聯的複雜情況是我使用的命名空間,解決方案似乎相對簡單 - 主要是在協會的accounts_account一側添加foreign_key:選項。

我用這個源爲起點:http://joeswann.co.nz/rails-4-has_many-polymorphic-relationships,與Article適於每個用戶類型(Users::SuperAdminUserUsers::AdminUser,和Users::StandardUserTag適於Accounts::AccountTagTarget適於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) 
相關問題