custom assignable primary key and mass assignment filter/warning #4291

sanderhahn opened this Issue Jan 4, 2012 · 4 comments

3 participants


The MassAssignmentSecurity triggers a warning and seems to clear the primary key when you use a custom set_primary_key and disable the id auto primary key.

Loading development environment (Rails 3.1.3)

ruby-1.9.2-p290 :001 >{code: 'USD', name: 'Dollar'})
WARNING: Can't mass-assign protected attributes: code
 => #[CurrencyUnit code: nil, name: "Dollar", created_at: nil, updated_at: nil]

ruby-1.9.2-p290 :002 > CurrencyUnit.primary_key
 => "code" 

You don't receive any warnings when models have a default id key.

Ruby on Rails member

Do you mind creating a test case for this?


Well primary keys are protected by default per:

So the errant behavior here is that a warning is emitted for one case but not the other?


I can confirm that a warning is emitted with both nondefault primary keys and the default id key

In a freshly generated rails app running 3.1.3

ruby-1.9.2-p180-patched :001 > 5)
WARNING: Can't mass-assign protected attributes: id
 => #<Post id: nil, name: nil, created_at: nil, updated_at: nil> 
ruby-1.9.2-p180-patched :002 > Rails.version
 => "3.1.3" 

This issue should be closed.


Thanks, i misunderstood that field became protected because it became the primary key. Sorry, issue closed.

@sanderhahn sanderhahn closed this Jan 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment