before_destroy and protecting some records

I want to delete some "Accounts' that have dependent "Users", however I
want to skip users tagged is_power. I want to do this by resetting the
users to a master account id.

In my User model I have the following code:

- - - - - - - - - - - - -

before_destroy :reset_power_users

def reset_power_users
  users = User.find_by_account_id_and_is_power(account.id, true)
  users.each {|user| update_attribute(:account_id, 1)}
end

- - - - - - - - - - - - -

I'm not sure the variables I'm passing are correct, but it's not
throwing and error and deleting all users under the current account.

Thanks in advance for taking a look :slight_smile:

before_destroy :reset_power_users

def reset_power_users
users = User.find_by_account_id_and_is_power(account.id, true)
users.each {|user| update_attribute(:account_id, 1)}
end

- - - - - - - - - - - - -

I'm not sure the variables I'm passing are correct, but it's not
throwing and error and deleting all users under the current account.

Well at the very least it's not working because find_by_xxx is
analogous to find :first (ie returns a single record or nil). The
find :all equivalent is find_all_by_xxx

Fred