How to say ruby ​​on rails, and not insert into a column?

I have a table with merge replication (SQL Server 2005). There is a rowguid column . I want RoR to ignore this column and not to insert or include it when creating the INSERT statement.

+5
source share
3 answers

See this ticket for a patch for rails. You can add the following code to a new file /config/initializers/hidden_columns.rb:

require "activerecord"

class << ActiveRecord::Base 
  def hidden_columns(*hidden) 
    write_inheritable_array("hidden_column", hidden.collect(&:to_s)) 
  end

  def columns_hidden
    read_inheritable_attribute("hidden_column") || [] 
  end 

  def columns 
    unless defined?(@columns) && @columns 
      @columns = connection.columns(table_name, "#{name} Columns").delete_if {|c| columns_hidden.member?(c.name) } 
      @columns.each {|column| column.primary = column.name == primary_key} 
    end 
    @columns 
  end
end

Then you can write:

hidden_columns :rowguid

in the respective models.

+3
source

- , (). , rails SQL Server. , / , ...

+1

The answer is the same as above

The method must be defined as a method of the class http://gist.github.com/504745

0
source

All Articles