Hi, I''ve been helping Jean-Christophe Michel with the Better Nested Set plugin (http://opensource.symetrie.com/trac/better_nested_set), and we need a way to make ActiveRecord exclude certain columns from the UPDATE statement. My solution so far is to override the update method in AR, forcing it to ignore the columns in question. Is this a reasonable way to do things? It seems sort of heavy-handed. I''ve included the code in question below. The situation is a little hard to explain without discussing how a nested set works, but I''ll try: there are two index columns which define a tree structure, and whose values are updated by direct SQL statements only, and never through AR. No big deal, you say: just override the setter methods for those attributes. And that is exactly what we do. But the problem is this: the index columns get updated for large portions of the table any time the tree structure is altered, so the index values of an AR object can easily become stale. If the record is then saved, the stale index values are written to the database, corrupting the index. Any input is appreciated. Krishna # override ActiveRecord''s ''update'' to make update call my ''special_attributes_with_quotes'' def update #:nodoc: connection.update( "UPDATE #{self.class.table_name} " + "SET #{quoted_comma_pair_list(connection, special_attributes_with_quotes(false))} " + "WHERE #{self.class.primary_key} = #{quote_value(id)}", "#{self.class.name} Update" ) end # exclude the lft/rgt columns from update statements def special_attributes_with_quotes(include_primary_key true) #:nodoc: attributes.inject({}) do |quoted, (name, value)| if column = column_for_attribute(name) quoted[name] = quote_value(value, column) unless (!include_primary_key && column.primary) || [acts_as_nested_set_options[:left_column], acts_as_nested_set_options[:right_column]].include?(column.name) end quoted end end # i couldn''t figure out how to call attributes_with_quotes without cutting and # pasting this private method in. # Quote strings appropriately for SQL statements. def quote_value(value, column = nil) #:nodoc: self.class.connection.quote(value, column) end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---