jashmenn/activeuuid — Issue #5: Relationship ids coming in as strings from mass assignment.
Author: zorn
Created: 2011-12-27 21:34:57+00:00
State: open

So I have a Rails project and UUIDs as primary key is a requirement and I'm giving this gem a shot.

One issue I've ran into is the relational ids. Take your Email example...

~~~~
class Email < ActiveRecord::Base
include ActiveUUID::UUID
belongs_to :sender
end
~~~~

Let's also assume `:sender` is using ActiveUUID.

If I was editing an Email object using a typical Rails form I'd probably list a bunch of senders in a pull down and use the full string UUID in the option tag. When coming back in through mass assignment in a typical form the sender_id on the Email instance would be a string object. Are there any plans to add a flag or something to have this gem auto process mass assignment ids and rebuild them as UUID objects.

For now I've added the follow as a `before_validation` method:

~~~~
# Because these ids come back in as strings from froms we need to reparse them to become UUID objects
def fix_uuid_strings
if !self.session_description_id.nil? && self.session_description_id.class != UUIDTools::UUID
self.session_description_id = UUIDTools::UUID.parse(self.session_description_id)
end
end
~~~~