Skip to content

Conversation

@nhasselmeyer
Copy link
Contributor

Given I have the following setup

class UserUpdater < ActiveType::Object
  nests_many :users
end

Now, I have a route that updates all admins. I want to use the UserUpdater like this:

updater = UserUpdater.new(users: User.admin.includes(:association).to_a)
updater.attributes = {
  'users_attributes' => {
    '1' => { 'id' => '1', last_review: '2025-09-09' },
    '2' => { 'id' => '4', last_review: '2025-09-09' },
  }
}

ActiveType doesn't use the given user array to locate the users and loads all given users seperately, causing far more database queries than needed. The issue seems to be that it checks all existing records for whether their id equals the id from the attributes hash. But the id in the loaded records is an integer, the id in the hash is a string, so they never equal.

This PR converts both the id of the existing record and the given id to a string before comparing. This should eliminate this error and will also work with string UUIDs.

@kratob kratob merged commit 2076c74 into main Sep 11, 2025
9 checks passed
@kratob
Copy link
Member

kratob commented Sep 11, 2025

Thank you!
Released as 2.6.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants