This project is archived and is in readonly mode.
after_create callback is not called in an association
-
99miles
This is working fine for me -- the callback is getting called in both cases.
-
Rafael Mendonça França
I tried it again in a new Rails 3 application and I have the same behavior.
class Order < ActiveRecord::Base has_many :items, :class_name => 'OrderItem' endclass OrderItem < ActiveRecord::Base belongs_to :order after_create :update_value private def update_value self.order.value += self.price end endIn Rails console:
>> order => #<Order id: 1, value: nil, created_at: "2010-10-15 22:21:36", updated_at: "2010-10-15 22:21:36"> >> order.value = 0 >> order.save! => true >> order.items.create(:price => 10) => #<OrderItem id: 1, price: 10, order_id: 1, created_at: "2010-10-15 22:22:54", updated_at: "2010-10-15 22:22:54"> >> order => #<Order id: 1, value: 0, created_at: "2010-10-15 22:21:36", updated_at: "2010-10-15 22:22:52"> >> order.items.create(:price => 10) => #<OrderItem id: 2, price: 10, order_id: 1, created_at: "2010-10-15 22:23:23", updated_at: "2010-10-15 22:23:23"> >> order => #<Order id: 1, value: 0, created_at: "2010-10-15 22:21:36", updated_at: "2010-10-15 22:22:52"> >> OrderItem.create!(:order => order, :price => 20) => #<OrderItem id: 3, price: 20, order_id: 1, created_at: "2010-10-15 22:23:48", updated_at: "2010-10-15 22:23:48"> >> order => #<Order id: 1, value: 20, created_at: "2010-10-15 22:21:36", updated_at: "2010-10-15 22:22:52"> -
Ryan Bigg
- Tag changed from sheepskin boots, callbacks to callbacks
- Importance changed from to Low
Automatic cleanup of spam.
-
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale