Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING: Can't mass-assign these protected attributes: id (ar-extensions)

I'm using Rails 2.3.5 and AR-extensions 0.9.3

I'm trying to bulk insert from one table to another table located on a different server / database. I don't want anything overwritten though. Just a simple insert at the end of the new table is good enough.

I noticed that I get this warning message: WARNING: Can't mass-assign these protected attributes: id

My former entries are being overwritten.. so how do I work around this?

Thanks!

Edit: Figured it out. Looks like all I have to is define an array of attributes I want (Excluding id) and feed that into the import function.

Update:

tableA_items = TableA.find(:all)

TableB.establish_connection("other_server")
TableB.import tableA_items
like image 499
Tommy Avatar asked Jan 31 '26 19:01

Tommy


1 Answers

This bug existed in ar-extensions (up to 0.9.5 in which it was fixed) and activerecord-import (up to 0.2.7 in which it was fixed).

ar-extensions is used for Rails 2.x. activerecord-import should be used for Rails 3.x. They support the same APIs.

like image 94
Zach Dennis Avatar answered Feb 02 '26 09:02

Zach Dennis