Sha256: fbce25f01fdc07377e9a92eaea939d026019b95a641c7cc4e1c75407201fb0a3

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Animal
  class Human < ActiveRecord::Base
    has_many :pigs

    has_many :ownerships
    has_many :chickens, :through => :ownerships
  end
  class Pig < ActiveRecord::Base
    belongs_to :human
  end

  class Chicken < ActiveRecord::Base
    has_many :ownerships
    has_many :humans, :through => :ownerships
  end

  class Ownership < ActiveRecord::Base
    belongs_to :human
    belongs_to :chicken

    validates_uniqueness_of :chicken_id, :scope => :human_id
  end

end

class GoldPiece < ActiveRecord::Base;   belongs_to :treasure  end
class Matey < ActiveRecord::Base;       belongs_to :pirate    end
class Parrot < ActiveRecord::Base;      belongs_to :pirate; attr_accessor :cloned_from_id end
class BattleShip < ActiveRecord::Base;  has_many   :pirates, :as => :ship end

class Pirate < ActiveRecord::Base
  belongs_to :ship, :polymorphic => true

  has_many :mateys
  has_many :treasures, :foreign_key => 'owner'
  has_many :gold_pieces, :through => :treasures
  has_one :parrot

  attr_accessor :cloned_from_id
end

class Treasure < ActiveRecord::Base
  belongs_to :pirate, :foreign_key => :owner
  belongs_to :matey
  has_many :gold_pieces
end

class Person < ActiveRecord::Base
  has_and_belongs_to_many :cars
end

class Car < ActiveRecord::Base
  has_and_belongs_to_many :people
end

class ChildWithValidation < ActiveRecord::Base
  belongs_to :parent, :class_name => 'ParentWithValidation'
  validates :name, :presence => true
end

class ParentWithValidation < ActiveRecord::Base
  has_many :children, :class_name => 'ChildWithValidation'
  validates :name, :presence => true
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
deep_cloneable-1.5.1 test/models.rb