Rails has_many通过多态与命名空间模型

时间:2017-02-11 06:36:00

标签: ruby-on-rails ruby namespaces has-many-through polymorphic-associations

我的课程和迁移如下。不确定我做错了什么,我是否设置了关联错误或者我没有使用正确的属性/方法来返回我期望的记录。例如,如何获取{{1}的所有成员(super_admin_usersadmin_users standard_users)的列表}}?在Rails控制台中,如果我尝试account,我会得到以下内容:

Accounts::Account.first.users_account_members

如果我尝试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_useradmin_user)成员的列表?

以下是我的关联及其迁移的类:

应用/模型/帐户/ account.rb

standard_user

应用/模型/用户/ super_admin_user.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

应用/模型/用户/ 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

应用/模型/用户/ standard_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

应用/模型/帐户/ account_membership.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

分贝/迁移/ 20170203001000_create_users_super_admin_user.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

分贝/迁移/ 20170203001100_create_users_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

分贝/迁移/ 20170203001200_create_users_standard_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

分贝/迁移/ 20170204001000_create_accounts_account.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

分贝/迁移/ 20170204001100_create_accounts_account_membership.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

2 个答案:

答案 0 :(得分: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

之类的内容

答案 1 :(得分:0)

因此,这种关联的复杂性是我对命名空间的使用,并且解决方案似乎相对简单 - 主要是在关联的foreign_key:侧添加了accounts_account选项。 / p>

我使用此来源作为起点:http://joeswann.co.nz/rails-4-has_many-polymorphic-relationships,其中Article适用于每种用户类型(Users::SuperAdminUserUsers::AdminUserUsers::StandardUser ),Tag适应Accounts::AccountTagTarget适应Accounts::AccountMembership。然后,我在需要的class_name:foreign_key:选项中添加了适应类的命名空间。

此外,我向users_account_members类添加了一个实例方法Accounts::Account,以便检索所有用户类型的帐户成员。我想我想知道如果我无法检索所有用户类型的所有帐户成员而不添加此内容,那么这种多态关系的优点是什么 方法。似乎我可以通过has_many与每个用户类型之间的单独Accounts::Account关系来实现相同的目标。

修订后的类看起来如下(迁移没有变化):

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: "garnold0@spotify.com", 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: "garnold0@spotify.com", 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: "ncruz5@huffingtonpost.com", 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: "hlaned@whitehouse.gov", 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: "rharveyi@tripadvisor.com", 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: "ghamiltonl@sciencedirect.com", 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: "jkellyq@alexa.com", 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: "garnold0@spotify.com", 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: "ncruz5@huffingtonpost.com", 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: "hlaned@whitehouse.gov", 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: "rharveyi@tripadvisor.com", 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: "ghamiltonl@sciencedirect.com", 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: "jkellyq@alexa.com", 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: 'garnold0@spotify.com',      first_name: 'Gregory', last_name: 'Arnold',   username: 'garnold0')
Users::SuperAdminUser.create(email: 'lsanders1@time.com',        first_name: 'Lisa',    last_name: 'Sanders',  username: 'lsanders1')
Users::SuperAdminUser.create(email: 'ssanders2@ucsd.edu',        first_name: 'Scott',   last_name: 'Sanders',  username: 'ssanders2')
Users::SuperAdminUser.create(email: 'aroberts3@g.co',            first_name: 'Anthony', last_name: 'Roberts',  username: 'aroberts3')
Users::SuperAdminUser.create(email: 'probinson4@bandcamp.com',   first_name: 'Paula',   last_name: 'Robinson', username: 'probinson4')
Users::SuperAdminUser.create(email: 'ncruz5@huffingtonpost.com', first_name: 'Nicole',  last_name: 'Cruz',     username: 'ncruz5')
Users::SuperAdminUser.create(email: 'gandrews6@cyberchimps.com', first_name: 'George',  last_name: 'Andrews',  username: 'gandrews6')
Users::SuperAdminUser.create(email: 'nwilson7@deviantart.com',   first_name: 'Nicole',  last_name: 'Wilson',   username: 'nwilson7')
Users::SuperAdminUser.create(email: 'aedwards8@qq.com',          first_name: 'Anne',    last_name: 'Edwards',  username: 'aedwards8')
Users::SuperAdminUser.create(email: 'rdavis9@geocities.jp',      first_name: 'Ronald',  last_name: 'Davis',    username: 'rdavis9')

Users::AdminUser.create(email: 'lhawkinsa@icio.us',            first_name: 'Lisa',    last_name: 'Hawkins',  username: 'lhawkinsa')
Users::AdminUser.create(email: 'htaylorb@imdb.com',            first_name: 'Helen',   last_name: 'Taylor',   username: 'htaylorb')
Users::AdminUser.create(email: 'gtaylorc@unblog.fr',           first_name: 'Gregory', last_name: 'Taylor',   username: 'gtaylorc')
Users::AdminUser.create(email: 'hlaned@whitehouse.gov',        first_name: 'Henry',   last_name: 'Lane',     username: 'hlaned')
Users::AdminUser.create(email: 'hphillipse@howstuffworks.com', first_name: 'Harry',   last_name: 'Phillips', username: 'hphillipse')
Users::AdminUser.create(email: 'jgonzalesf@com.com',           first_name: 'Jeffrey', last_name: 'Gonzales', username: 'jgonzalesf')
Users::AdminUser.create(email: 'ljamesg@sfgate.com',           first_name: 'Lori',    last_name: 'James',    username: 'ljamesg')
Users::AdminUser.create(email: 'rhillh@gnu.org',               first_name: 'Roger',   last_name: 'Hill',     username: 'rhillh')
Users::AdminUser.create(email: 'rharveyi@tripadvisor.com',     first_name: 'Raymond', last_name: 'Harvey',   username: 'rharveyi')
Users::AdminUser.create(email: 'sperryj@mit.edu',              first_name: 'Stephen', last_name: 'Perry',    username: 'sperryj')

Users::StandardUser.create(email: 'mblackk@prnewswire.com',       first_name: 'Michelle',   last_name: 'Black',     username: 'mblackk')
Users::StandardUser.create(email: 'ghamiltonl@sciencedirect.com', first_name: 'Gary',       last_name: 'Hamilton',  username: 'ghamiltonl')
Users::StandardUser.create(email: 'cgraym@about.com',             first_name: 'Chris',      last_name: 'Gray',      username: 'cgraym')
Users::StandardUser.create(email: 'jbradleyn@wikispaces.com',     first_name: 'Jacqueline', last_name: 'Bradley',   username: 'jbradleyn')
Users::StandardUser.create(email: 'jpayneo@netscape.com',         first_name: 'Joseph',     last_name: 'Payne',     username: 'jpayneo')
Users::StandardUser.create(email: 'drodriguezp@apache.org',       first_name: 'Debra',      last_name: 'Rodriguez', username: 'drodriguezp')
Users::StandardUser.create(email: 'jkellyq@alexa.com',            first_name: 'Jonathan',   last_name: 'Kelly',     username: 'jkellyq')
Users::StandardUser.create(email: 'creynoldsr@wired.com',         first_name: 'Cheryl',     last_name: 'Reynolds',  username: 'creynoldsr')
Users::StandardUser.create(email: 'kbarness@pbs.org',             first_name: 'Kathleen',   last_name: 'Barnes',    username: 'kbarness')
Users::StandardUser.create(email: 'ahansent@chron.com',           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)