Jonathan Rochkind wrote:
> So I've got an ActiveRecord model pointing to a MySQL db, with an
> auto-serialized column ("serialize :columnName").
>
> Thing is, MySQL, depending on how it's configured (like, by default),
> has a bad habit of just truncating your data if it's too wide for the
> column, with no error raised. Yeah, I can probably reconfigure MySQL
> and/or my AR connection to it. But I'm wanting to distribute this code
> to all kinds of people who won't think of that or won't want to do that,
> I'd really like it to work with the default setup.
>
> But obviously, if a yaml serialization gets truncated, it's not going to
> unserialize very well.
>
> At the point of insert/update, is there any good way for me to detect
> that the serialization was too big for the column, even though MySQL
> isn't complaining?
This may do it:
def validate
if columnName.to_yaml > column_for_attribute(:columnName).limit
errors.add(:columnName, 'columnName is too big to be serialized')
end
end
It'd be good if something like this was added automatically by
serialize.
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---