Rename field_changed? to _field_changed? so that users can create a field named field #3544

Merged
merged 2 commits into from Feb 14, 2012

Projects

None yet

4 participants

@amatsuda
Ruby on Rails member

This patch allows users to create a field named field in AR models.

Without this patch, AR raises ActiveRecord::DangerousAttributeError: field_changed? is defined by ActiveRecord when trying to define a "_changed?" suffixed method for every attribute https://github.com/rails/rails/blob/b454601/activemodel/lib/active_model/dirty.rb#L92

This should be fixed because
1) "field" fields didn't cause any error on AR 2. So, this is a regression.
2) AR's field_changed? is a private method. Why should attribute names be restricted by the framework's internal method name?

@tenderlove
Ruby on Rails member

Seems good, but shouldn't we have a test to ensure against another regression?

@amatsuda amatsuda added a commit to amatsuda/rails that referenced this pull request Nov 8, 2011
@amatsuda amatsuda A test case for GH #3544 to ensure that a field named field works fine 658c71c
@amatsuda
Ruby on Rails member

@tenderlove Thank you for reviewing. Just added a test case that fails without fdfe358.

@amatsuda
Ruby on Rails member

Rebased against current master. @tenderlove, could you merge this?

@tenderlove tenderlove merged commit 848c3d4 into rails:master Feb 14, 2012
@clemens

I don't see this in the 3-2-stable branch so I assume it hasn't been backported. Could someone backport it? Would be hell of useful.

@steveklabnik
Ruby on Rails member
@yahonda yahonda referenced this pull request in rsim/oracle-enhanced Nov 21, 2012
Merged

Remove field_changed? method from rails4 branch #254

@barendt barendt pushed a commit to PMACS/oracle-enhanced that referenced this pull request Nov 18, 2013
@yahonda yahonda To support _field_changed? method renamed from field_changed? c7549b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment