Sha256: 620f066f66c0460a2c43dc4cd66cb2d7853cbe13d2752f0ee6ffc1cbd9f485f6

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 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
end

class Label
  include Mongoid::Document
  field :name
  embedded_in :artist
  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

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-eager-loading-0.3.1 spec/models/callbacks.rb
mongoid-eager-loading-0.3.0 spec/models/callbacks.rb