lib/moribus/tracked_behavior.rb
def current_to_false_sql_statement
      klass              = self.class
      lock_column_name   = klass.locking_column
      lock_value         = current_lock_value
      lock_column        = if lock_value
                             klass.columns.detect { |c| c.name == lock_column_name }
                           else
                             nil
                           end
      quoted_lock_column = klass.connection.quote_column_name(lock_column_name)

      "UPDATE #{klass.quoted_table_name} " \
      "SET \"is_current\" = #{klass.connection.quote(false)} ".tap do |sql|
        sql << "WHERE #{klass.quoted_primary_key} = " \
               "#{klass.connection.quote(@_before_to_new_record_values[:id])}"

        if lock_value
          sql << " AND \"is_current\" = #{klass.connection.quote(true)}"
          sql << " AND #{quoted_lock_column} = #{klass.connection.quote(lock_value)}"
        end
      end
    end
# Generate SQL statement to be used to update 'is_current' state of record to false.
# TODO: need to find way to track stale objects
Generate SQL statement to be used to update 'is_current' state of record to false.
TODO: need to find way to track stale objects
Generate SQL statement to be used to update ' is_current ' state of record to false . TODO : need to find way to track stale objects
def current_to_false_sql_statement
      klass              = self.class
      lock_column_name   = klass.locking_column
      lock_value         = current_lock_value
      lock_column        = if lock_value
                             klass.columns.detect { |c| c.name == lock_column_name }
                           else
                             nil
                           end
      quoted_lock_column = klass.connection.quote_column_name(lock_column_name)
      "UPDATE #{klass.quoted_table_name} " \
      "SET \"is_current\" = #{klass.connection.quote(false)} ".tap do |sql|
        sql << "WHERE #{klass.quoted_primary_key} = " \
               "#{klass.connection.quote(@_before_to_new_record_values[:id])}"
        if lock_value
          sql << " AND \"is_current\" = #{klass.connection.quote(true)}"
          sql << " AND #{quoted_lock_column} = #{klass.connection.quote(lock_value)}"
        end
      end
    end
def current_to_false_sql_statement klass = self . class lock_column_name = klass . locking_column lock_value = current_lock_value lock_column = if lock_value klass . columns . detect { | c | c . name == lock_column_name } else nil end quoted_lock_column = klass . connection . quote_column_name ( lock_column_name ) "UPDATE #{klass.quoted_table_name} " "SET \"is_current\" = #{klass.connection.quote(false)} " . tap do | sql | sql << "WHERE #{klass.quoted_primary_key} = " "#{klass.connection.quote(@_before_to_new_record_values[:id])}" if lock_value sql << " AND \"is_current\" = #{klass.connection.quote(true)}" sql << " AND #{quoted_lock_column} = #{klass.connection.quote(lock_value)}" end end end
Generate SQL statement to be used to update 'is_current' state of record to false.
Generate SQL statement to be used to update ' is_current ' state of record to false .