开发者

In Rails 2, how would I define a callback method when adding models in a has_many relationship?

开发者 https://www.devze.com 2023-01-17 04:28 出处:网络
In my project I have a Forum that has many Topics, and each Topic has many Posts. When I add a Post to a Topic, I would like to update a timestamp column in the Topic model to record when the last Pos

In my project I have a Forum that has many Topics, and each Topic has many Posts. When I add a Post to a Topic, I would like to update a timestamp column in the Topic model to record when the last Post was added to the Topic. How can I do this?

Thank you f开发者_开发知识库or looking!


You should use an after_create callback in the Post model.


you can use the after_save callback in the model => http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

0

精彩评论

暂无评论...
验证码 换一张
取 消