标签: ruby-on-rails ruby activerecord
假设我有2个模型,用户和组
user belongs_to :group group has_many :users
有没有办法在组被销毁之前/之后将user.group属性设置为另一个值?
答案 0 :(得分:0)
class Group < ActiveRecord::Base has_many :users before_destroy -> { users.each {|u| u.group = nil; u.save}} end