Frederick Cheung wrote:
> On 3 Mar 2009, at 16:41, James Byrne wrote:
>> I would like to pass the following SQL fragment as part of an AR save
>> call to TestTime objects.  How and where would I do this in the model?
>>
> Nothing builtin for that as far as I know. If you dig around in the AR
> source you may find a suitable method to overide/piggyback on
> 

In AR::Base I find this:

      def update(attribute_names = @attributes.keys)
        quoted_attributes = attributes_with_quotes(false, false, 
attribute_names)
        return 0 if quoted_attributes.empty?
        connection.update(
          "UPDATE #{self.class.quoted_table_name} " +
          "SET #{quoted_comma_pair_list(connection, quoted_attributes)} 
" +
          "WHERE #{connection.quote_column_name(self.class.primary_key)} 
= #{quote_value(id)}",
          "#{self.class.name} Update"
        )
      end

So, I think that something along the lines of:

module HLLARUpdateSQL
  def self.included(base)

      def update_sql(id,fragment)
        return 0 unless fragment
        connection.update(
          "UPDATE #{self.class.quoted_table_name} " +
          "SET #{fragment} " +
          "WHERE #{connection.quote_column_name(self.class.primary_key)} 
" +
            "#{quote_value(id)}",
          "#{self.class.name} Update"
        )

      end
  end
end

might serve.  Your thoughts?
-- 
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