On 22 Oct 2008, at 10:23, 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.
>
You're almost certainly not using Rails 1.8.x because that version has  
never existed (but you are probably running ruby 1.8.x (where x is  
probably 6))
Patches can be submitted at rails.lighthouseapp.com and/or discussed  
on the rubyonrails-core google group mailing list

Fred

> 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
>
> Mark Reginald James wrote:
>> Jonathan Rochkind wrote:
>>> itself?
>> Yeah, the double yaml is a waste, but don't worry about it
>> unless this is being done sufficiently often to slow down
>> your app in a way that generates more work or cost.
>>
>> See if you can come up for a patch for Rails that automatically
>> adds a such a validation for serialized attributes, where this
>> validation method and the attributes_with_quotes method that
>> generates the DB request both draw from a cache of YAMLized
>> attribute values.
>>
>> --
>> Rails Wheels - Find Plugins, List & Sell Plugins -
>> http://railswheels.com
>
> -- 
> Posted via http://www.ruby-forum.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
-~----------~----~----~----~------~----~------~--~---

Reply via email to