I have a table, with merge replication on it (SQL Server 2005). There is a rowguid column. I want RoR to ignore this column, and not insert into this, and not include this when generating the INSERT statement.
See this ticket which proposes a patch to 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 concerned models.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With