>   class Model
>>>     plugin :typecast_on_load, :id
>>>     def id=(v)
>>>       v.is_a?(String) ? super(UUIDTools::UUID.parse_raw(v) : super
>>>     end
>>>   end
>>>   class UUID
>>>     def sql_literal(ds)
>>>       "uuid2binary(#{ds.literal(to_s)})"
>>>     end
>>>   end
>>>
>>
I've actually had time to attempt implementing this. The problem 
with typecast_on_load is that I end up with this:

m1.id => "db7ee4c0-cac5-11e1-85e9-b8f6b1134127"
m1.id.class => Sequel::SQL::Blob

It's still being converted back into Sequel::SQL::Blob and as such the UUID 
literalizer doesn't end up doing anything.

I'm halfway temped to override or create a literalizer 
for Sequel::SQL::Blob since the only binary fields in use are these.

I pointed out the uuid2binary, but we also have binary2uuid which is 
probably self explanatory. What could I do to force all binary(16) fields 
to use those functions transparently in the models?

Even using prepared statements, when I try and do an association that uses 
a UUID key, I run into the same troubles we mentioned before:

m1.assoc_models => nil
SELECT * FROM `assoc_models` WHERE (`assoc_models`.`model_id` = '?|T?a?D+́ 
')


-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/vKjb4rMxNlQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to