Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deleting attributes from ActiveRecord model

I'm migrating data between two activerecord connections, I've got my models all setup correctly so I can read from say Legacy::Tablename and Tablename and insert it into the new table.

The problem I have is my new model doesn't have all of the attributes that are in the legacy model so I get an 'unknown attribute' when I try to create a record in the new model via;

legacy_users = Legacy::User.all
legacy_users.each do |legacy_user|
  User.create legacy_user.attributes
end

however if I try to remove the offending attribute it still doesn't work eg.

legacy_user.attributes.delete 'some_attribute'

Can anyone offer any pointers?

like image 620
John Beynon Avatar asked Dec 12 '22 15:12

John Beynon


1 Answers

How about attributes.except(:some_attribute)?

like image 77
oliverbarnes Avatar answered Dec 24 '22 03:12

oliverbarnes