Can't import protected attributes
Reported by markisisme | July 1st, 2009 @ 12:30 AM
"import" throws warnings like the following when trying to set protected attributes:
WARNING: Can't mass-assign these protected attributes: id
This has been reported as part of the issue in other tickets such as in #13
It looks like this is due to the way ar-extensions builds the
model instances, with new(), in order to run validations. Rails
throws the warnings and removes the protected attributes from the
instances, and so they are never imported.
This is reasonable behavior in some sense, but you (or at least I) may want to set protected attributes in some scenarios. I committed a patch that allows this behavior through the use of a :write_protected_attrs option.
The code is essentially just preempting the remove_attributes_protected_from_mass_assignment() call in active_record/base.rb.
Comments and changes to this ticket
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and
enhance the functionality of ActiveRecord. It starts by adding better
find support for ActiveRecord. It then adds mass data import
capabilities which are highly efficient and lastly it supports to_csv
functionality.
It also introduces a cool concept of creating easily extendable pieces
of ActiveRecord functionality, so developers don't have to understand
ActiveRecord internals or have the fear of breaking ActiveRecord
itself.