You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Activeuuid defaults the primary key of new records to a UUID with a value of "00000000-0000-0000-0000-000000000000" whereas ActiveRecord expects all keys of new records to be nil.
This breaks accepts_nested_attributes_for because, seeing the non-nil UUID, ActiveRecord tries to find the non-existent record (with "00000000-0000-0000-0000-000000000000" as an ID).
The text was updated successfully, but these errors were encountered:
Here's a hacky work-around (since we couldn't work out where the UUID assignment was happening in the library's metaprogrammed magic).
In lib/ext/active_record.rb:
# For details on extending ActiveRecord see:# http://stackoverflow.com/questions/2328984/rails-extending-activerecordbasemoduleActiveRecordExtensionextendActiveSupport::ConcernincludeddoincludeActiveUUID::UUIDafter_initialize:delete_zeroed_uuidbefore_create:set_idendprivatedefdelete_zeroed_uuidself.id=nilifzeroed_uuid?enddefset_idreturnunlesszeroed_uuid?self.id=SecureRandom.uuidenddefzeroed_uuid?id.to_s == '00000000000000000000000000000000' ||
id.to_s == '00000000-0000-0000-0000-000000000000'endend# include the extensionActiveRecord::Base.send(:include,ActiveRecordExtension)unlessFile.basename($PROGRAM_NAME) == 'rake' && ARGV.include?('db:migrate')
ivanoblomov
changed the title
Default primary key value causes incompatibilities with accepts_nested_attributes_for
Default primary key value is incompatible with accepts_nested_attributes_for
Jun 2, 2015
Activeuuid defaults the primary key of new records to a UUID with a value of "00000000-0000-0000-0000-000000000000" whereas ActiveRecord expects all keys of new records to be nil.
This breaks accepts_nested_attributes_for because, seeing the non-nil UUID, ActiveRecord tries to find the non-existent record (with "00000000-0000-0000-0000-000000000000" as an ID).
The text was updated successfully, but these errors were encountered: