Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A model attribute named "type" is automatically inserted into ActiveModel::MassAssignmentSecurity::BlackList

I do NOT have config.active_record.whitelist_attributes = true in application config. And I have attr_protected() in the model class. However, I notice that the id and type attributes are automatically inserted into ActiveModel::MassAssignmentSecurity::BlackList. This makes sense for id attribute since we do not want to set id in a mass assignment, but why this is also true for the type attribute?

like image 868
powerboy Avatar asked Jan 16 '23 09:01

powerboy


1 Answers

The attribute type is used by active record when you are using single table inheritance between active record models, that's why it's in the black list. It holds the name of the class that was saved so Rails knows what kind of object was saved.

like image 72
Maurício Linhares Avatar answered Jan 30 '23 18:01

Maurício Linhares