aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/owner.rb
blob: cf24502d3a70b3f6916fa3658adc1389308cda5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Owner < ActiveRecord::Base
  self.primary_key = :owner_id
  has_many :pets, -> { order 'pets.name desc' }
  has_many :toys, :through => :pets

  after_commit :execute_blocks

  def blocks
    @blocks ||= []
  end

  def on_after_commit(&block)
    blocks << block
  end

  def execute_blocks
    blocks.each do |block|
      block.call(self)
    end
    @blocks = []
  end
end