Sha256: 19162c0eefacb3cecee632c29e4d3e080584f04d0518b83541bc1d2f64b1569b

Contents?: true

Size: 888 Bytes

Versions: 5

Compression:

Stored size: 888 Bytes

Contents

class Artist
  include Mongoid::Document
  field :name
  embeds_many :songs
  embeds_many :labels

  before_create :before_create_stub
  after_create :create_songs

  protected
  def before_create_stub
    true
  end

  def create_songs
    2.times { |n| songs.create!(:title => "#{n}") }
  end
end

class Song
  include Mongoid::Document
  field :title
  embedded_in :artist, :inverse_of => :songs
end

class Label
  include Mongoid::Document
  field :name
  embedded_in :artist, :inverse_of => :labels
  before_validation :cleanup

  private
  def cleanup
    self.name = self.name.downcase.capitalize
  end
end

class ValidationCallback
  include Mongoid::Document
  field :history, :type => Array, :default => []
  validate do
    self.history << :validate
  end

  before_validation { self.history << :before_validation }
  after_validation { self.history << :after_validation }
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mongoid-eager-loading-0.2.0 spec/models/callbacks.rb
mongoid-eager-loading-0.1.2 spec/models/callbacks.rb
mongoid-eager-loading-0.1.1 spec/models/callbacks.rb
mongoid-eager-loading-0.1.0 spec/models/callbacks.rb
mongoid-locomotive-2.0.0.beta9 spec/models/callbacks.rb