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

Already on GitHub? Sign in to your account

Model method names should not conflict with attribute names #74

merged 1 commit into from Apr 19, 2013


None yet
3 participants

mike-burns commented Mar 15, 2013

No description provided.

@croaky croaky commented on an outdated diff Mar 15, 2013

@@ -56,6 +56,7 @@ Rails
change can be solved with another migration.
* Validate the associated `belongs_to` object (`user`), not the database
column (`user_id`).
+* Don't name methods after database columns in the same class.

croaky Mar 15, 2013


The guidelines are alphabetized within each section.


croaky commented Mar 15, 2013

Might be nice to add a "why" in the commit message.


mike-burns commented Mar 18, 2013

Should we have "why"s listed in the document itself, so people can more easily know what to watch for when they violate a best practice?


jferris commented Mar 18, 2013

I'd be concerned that we can succinctly describe the reasons for some of these guidelines, which would make the guide longer and harder to scan. Having the reasoning in the commit message means that you can use git blame to discover the original reason without having it in the actual guide body. Thoughts?


mike-burns commented Mar 18, 2013

That works. I'll push a commit with a longer explanation later.


mike-burns commented Mar 22, 2013

Squashed and gave an explanation.

@jferris jferris commented on an outdated diff Mar 22, 2013

@@ -54,6 +54,7 @@ Rails
`update_attribute`, and `toggle`.
* Don't change a migration after it has been merged into master if the desired
change can be solved with another migration.
+* Don't name methods after database columns in the same class.

jferris Mar 22, 2013


Can we rephrase this as an "Avoid" rule? I feel like that appropriately expresses the level of resistance developers should feel here.


jferris commented Mar 28, 2013

Good to merge.


jferris commented Apr 19, 2013

Was this ever merged?

@mike-burns mike-burns Model names distinct from database fields
Naming a method in an ActiveRecord object after the DB column causes
issues with Rails validations such as presence and uniqueness. Even if
the object does not have those validations now, wrapping an AR attribute
limits people in the future arbitrarily.

Instead of wrapping a column, instead name the column more simply. For
example, if you need to expose the receipt string as an `AppleReceipt`,
store the value as `encoded_receipt` or `receipt_string`, then provide a
`receipt` method that handles the wrapping.

@mike-burns mike-burns merged commit eea029c into master Apr 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment