I have a basic model class TestTime with no customization. class TestTime < ActiveRecord::Base end 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? "set c_time=current_time" (current_time is an SQL method, not a variable). -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 3 Mar 2009, at 16:41, James Byrne wrote:> > I have a basic model class TestTime with no customization. > > class TestTime < ActiveRecord::Base > end > > 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 Fred> "set c_time=current_time" > > (current_time is an SQL method, not a variable). > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- why is ActiveRecord tying to select nonex ID column?
- Why does ActiveRecord allow perception of success when updating an ID, however it doesn't really work(i.e. no change in database)?
- convert 12 time stamp to 24 hour
- Eager load associations in Oracle problem with more than 1000 records
- Plot time series data irregularly hourly-spaced