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)