Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有 2 个模型,用户和组
user belongs_to :group group has_many :users
有没有办法在组被销毁之前/之后将 user.group 属性设置为另一个值?
class Group < ActiveRecord::Base has_many :users before_destroy -> { users.each {|u| u.group = nil; u.save}} end