Jonathan Rochkind wrote:
> Here's a different (easier :) ) tack to monkey patching AR to solve this
> problem efficiently. Turns out the actual serialization is done in
> quote_value (and interestingly, done whether or not the column is
> declared serialized; the serialized decleration only effects
> de-serialization). Does anyone think this following approach is a good
> idea?
>
> Does anyone think it's a good enough idea I should submit it as a patch
> to AR? I've never submitted a patch before, not sure how it's done. I'm
> still using Rails 1.8.x, not sure if this is still a problem in Rails 2,
> so that might make it hard to submit a patch.
>
> class ActiveRecord::Base
> alias :old_quote_value :quote_value
> def quote_value(value, column = nil)
> if column && serialized_attributes[column.name]
> serialization = value.to_yaml
> raise new ActiveRecord::StatementInvalid("Can not serialize
> column #{column.name}, length #{serialization.length} is greater than
> column limit of #{column.limit}") if if serialization.length >
> column.limit
>
> "#{connection.quoted_string_prefix}'#{connection.quote_string(serialization)}'"
> else
> old_quote_value
> end
> end
> end
Jonathan, that's a fine solution if a database exception
is a better way to handle it than an automatic validation.
The validation route may however be more compatible with
the current save! idiom.
Also note that ActiveRecord trunk does the YAML conversion
in the attributes_with_quotes method instead.
--
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
-~----------~----~----~----~------~----~------~--~---