Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARNING: Can't mass-assign protected attributes: id #7

Closed
rockrep opened this issue Dec 13, 2010 · 10 comments
Closed

WARNING: Can't mass-assign protected attributes: id #7

rockrep opened this issue Dec 13, 2010 · 10 comments

Comments

@rockrep
Copy link

rockrep commented Dec 13, 2010

Using the Array version of import, i.e.

posts = [ BlogPost.new :author_name=>'Zach Dennis', :title=>'AREXT',
BlogPost.new :author_name=>'Zach Dennis', :title=>'AREXT2',
BlogPost.new :author_name=>'Zach Dennis', :title=>'AREXT3' ]
BlogPost.import posts

The :id attribute should be removed from the attribute_array prior to insert.

@zdennis
Copy link
Owner

zdennis commented Jan 11, 2011

Thanks rockrep, I'll check this out.

@jpfuentes2
Copy link

I'm getting this using AR model version as well.

@jpfuentes2
Copy link

A little poking around in the source shows that if I hand you a an AR model you rip out its attributes and then instantiate a new AR model later on. Seems like it be would more efficient to simply re-use the models I've already given you?

@zdennis
Copy link
Owner

zdennis commented Mar 19, 2011

What version of ActiveRecord are you getting this warning with? Also, what other gems might you be using? I cannot reproduce the warning with ActiveRecord 3.0.5.

@rockrep
Copy link
Author

rockrep commented Mar 23, 2011

I was using 3.0.3. I'll try again shortly once I upgrade to 3.0.5

@joeellis
Copy link

I'm actually getting the same error myself with activerecord 3.0.5 and the latest activerecord-import gem using the following code (if it helps):

items = [] 
deck.words.shuffle.each do |word|
  items << user.items.new(:word => word)
end
Item.import items

The import still seems to be working, but that warning is being issued in my logs.

@libin0120
Copy link

    if args.length == 2
      models = args.last
      column_names = args.first
    else
      models = args.first
      column_names = self.column_names.dup
    end

I think this line:

 column_names = self.column_names.dup

It having the ID column included by using default all columns from the DB table. What you can do is to put an array of columns as the first parameters to tell what column included, example:

Item.import [:name, :author, :price] items

However, the instructions did not mention this as the second parameters are models, not values.

@taylorstrait
Copy link

Is there an official workaround to this issue, as I am having it as well. Thanks for the great plugin!

@zdennis
Copy link
Owner

zdennis commented Apr 29, 2011

@everyone, This issue should no longer exist in activerecord-import 0.2.7 which was released tonight.

@jpfuentes2, your suggestion of re-using models is a good one. Would you mind putting that in its own issue?

Thanks everyone,

@zdennis zdennis closed this as completed Apr 29, 2011
@taylorstrait
Copy link

Confirming the issue is fixed in version 0.2.7 -- thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants