AH doesn't check if the ID is in use during object creation. This leads to a different behaviour between data= and multiple calls to the create method.
(byebug) Models::Point.data = [ {id:1}, {id:1}]
*** ActiveHash::IdError Exception: Duplicate ID found for record {:associated_stops=>[], :id=>1}
nil
(byebug) Models::Point.create({id:1})
#<Models::Point:0x000055f893355e30 @attributes={:id=>1, :associated_stops=>[]}>
(byebug) Models::Point.create({id:1})
#<Models::Point:0x000055f893369b60 @attributes={:id=>1, :associated_stops=>[]}>
(byebug) Models::Point.find(1)
#<Models::Point:0x000055f89330b560 @attributes={:id=>1, :associated_stops=>[]}>
^^^^^^^^^^^^^^^^^^ This is the very first object created by `data=`
Due to stringification of IDs it is not possible to retrieve an object if their id happens to be an integer as a string.
AH doesn't check if the ID is in use during object creation. This leads to a different behaviour between
data=
and multiple calls to thecreate
method.Due to stringification of IDs it is not possible to retrieve an object if their id happens to be an integer as a string.
The PR removes the ID stringification logic and add a
validate_unique_id
check to thecreate
method.