Hello,
when i create a record, User.create(:login=>'john', :password =>
'password'), active record behaviour is to include every of my fields
in the SQL query :
INSERT INTO users ("login", "password", "another_column",
"yet_another_column") VALUES('john', 'password', NULL, NULL)
But i want active record to just include filfulled fields in the
query:
INSERT INTO users ("login", "password") VALUES('john', 'password')
class ActiveRecord::Base
def self.ignore_column(column_name)
case column_name
when String, Symbol
self.columns_hash.delete(column_name.to_s)
self.columns.delete_if {|c| c.name == column_name.to_s}
when Regexp
self.columns_hash.delete_if { |k,v| column_name.match(k)}
self.columns.delete_if { |c| column_name.match(c.name)}
end
end
end
yes i need to read them :(. I already use same kind of hack on other
fields.
On Jan 9, 2:04 am, Stephan Wehner <rails-mailing-l...@andreas-s.net>
In that case you can extend the User model with a UserWrite model, which
has those columns hidden. The UserWrite model is only used by the
controller for updates/inserts.