Forum: Ruby on Rails Specify callbacks before associations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E5addfb886fa24edf1fcf9473a9b5a34?d=identicon&s=25 Jeremy Maziarz (jmaziarz)
on 2006-03-30 22:11
In the RoR API documentation
(http://api.rubyonrails.org/classes/ActiveRecord/Ca...) for
callbacks, there is a note that says:

"*IMPORTANT:* In order for inheritance to work for the callback queues,
you must specify the callbacks before specifying the associations.
Otherwise, you might trigger the loading of a child before the parent
has registered the callbacks and they wonâ??t be inherited."

Does this mean a model should be defined as:

class NetworkSegment < ActiveRecord::Base
  after_create :create_network_ipaddresses
  after_update :update_network_ipaddresses

  has_many :network_ipaddresses, :order => octet4

  #...
end

or

class NetworkSegment < ActiveRecord::Base
  has_many :network_ipaddresses, :order => octet4

  after_create :create_network_ipaddresses
  after_update :update_network_ipaddresses

  #...
end

Thanks,
-Jer
This topic is locked and can not be replied to.