【文件属性】:
文件名称:association_callbacks:ActiveRecord关联的回调
文件大小:10KB
文件格式:ZIP
更新时间:2021-05-02 09:55:45
Ruby
关联回调
提供一种将一个模型的定义为关联模型的方法。
例子
首先,两个简单的Article和Comment模型:
class Article < ActiveRecord :: Base
has_many :comments
end
class Comment < ActiveRecord :: Base
belongs_to :article
end
然后,您通常需要将Comment内容反规范化为Post ,反之亦然。 这是在帖子上反规范last_comment_at的标准方法:
class Comment < ActiveRecord :: Base
belongs_to :article
after_create :update_post_last_comment_at
after_destroy :update_post_last_comment_at
【文件预览】:
association_callbacks-master
----MIT-LICENSE(1KB)
----VERSION(6B)
----README.mdown(3KB)
----association_callbacks.gemspec(1KB)
----lib()
--------association_callbacks()
--------association_callbacks.rb(424B)
----Gemfile(39B)
----spec()
--------lib()
--------spec_helper.rb(405B)
--------mocks()
--------support()
----Rakefile(206B)
----.rspec(24B)
----.gitignore(74B)