Sha256: 0d0a049c8737b9e14a9b1b751c4ab56f7268b2403ca2c320362b6798ddd9b9df

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

class HmmCompany
  include Mongoid::Document

  field :p, type: Integer
  has_many :emails, primary_key: :p, foreign_key: :f, class_name: 'HmmEmail'

  # The addresses are added with different dependency mechanisms in tests:
  #has_many :addresses, class_name: 'HmmAddress', dependent: :destroy
end

class HmmEmail
  include Mongoid::Document

  field :f, type: Integer
  belongs_to :company, primary_key: :p, foreign_key: :f, class_name: 'HmmCompany'
end

class HmmAddress
  include Mongoid::Document

  belongs_to :company, class_name: 'HmmCompany'
end

class HmmOwner
  include Mongoid::Document

  has_many :pets, class_name: 'HmmPet', inverse_of: :current_owner

  field :name, type: String
end

class HmmPet
  include Mongoid::Document

  belongs_to :current_owner, class_name: 'HmmOwner', inverse_of: :pets, optional: true
  belongs_to :previous_owner, class_name: 'HmmOwner', inverse_of: nil, optional: true

  field :name, type: String
end

class HmmSchool
  include Mongoid::Document

  has_many :students, class_name: 'HmmStudent'

  field :district, type: String
  field :team, type: String
end

class HmmStudent
  include Mongoid::Document

  belongs_to :school, class_name: 'HmmSchool'

  field :name, type: String
  field :grade, type: Integer, default: 3
end

class HmmTicket
  include Mongoid::Document

  belongs_to :person
end

class HmmBus
  include Mongoid::Document

  has_many :seats, class_name: 'HmmBusSeat'
end

class HmmBusSeat
  include Mongoid::Document

  # No belongs_to :bus
end

class HmmTrainer
  include Mongoid::Document

  field :name, type: String

  has_many :animals, class_name: 'HmmAnimal', scope: :reptile
end

class HmmAnimal
  include Mongoid::Document

  field :taxonomy, type: String

  scope :reptile, -> { where(taxonomy: 'reptile') }

  belongs_to :trainer, class_name: 'HmmTrainer', scope: -> { where(name: 'Dave') }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-7.5.4 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.5.3 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.5.2 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.5.1 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.4.3 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.5.0 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.4.1 spec/mongoid/association/referenced/has_many_models.rb
mongoid-7.4.0 spec/mongoid/association/referenced/has_many_models.rb