mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
22 lines
383 B
Ruby
22 lines
383 B
Ruby
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
|