Skip to content

exists? to support ids which are strings#339

Open
mtmail wants to merge 1 commit intoactive-hash:masterfrom
mtmail:exists-string-ids
Open

exists? to support ids which are strings#339
mtmail wants to merge 1 commit intoactive-hash:masterfrom
mtmail:exists-string-ids

Conversation

@mtmail
Copy link

@mtmail mtmail commented Dec 11, 2025

It's my understanding ActiveRecord supports ids which are strings (for example UUIDs).

Currently (version 4.0)

class Car < ActiveHash::Base
  self.data = [
    id: 'bmw', title: 'BMW'
  ]
end

Car.find('bmw').is_a?(Car)
 => true
Car.find_by(id: 'bmw').is_a?(Car)
 => true
Car.where(id: 'bmw').first.is_a?(Car)

Car.exists?('bmw')
 => false
Car.exists?(id: 'bmw')
 => true

I would've expected Car.exists?('bmw') to return true.

In active_hash/base.rb I see ids are converted to string in several places for comparison, and the record_index also stores the keys as string.

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.

1 participant