Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't encourage usage of columns_hash #15976

Merged
merged 1 commit into from Jun 29, 2014

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Jun 29, 2014

As discussed in heartcombo/simple_form#1094,
we should not encourage usage of columns_hash, and instead provide an
alternate method to determine whether or not an attribute exists.

The language attribute was chosen over column since these are in the
AttributeMethods module.

As discussed in heartcombo/simple_form#1094,
we should not encourage usage of `columns_hash`, and instead provide an
alternate method to determine whether or not an attribute exists.

The language `attribute` was chosen over `column` since these are in the
`AttributeMethods` module.
@@ -202,12 +202,17 @@ def column_for_attribute(name)
if column.nil?
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
`column_for_attribute` will return a null object for non-existent columns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message might be too technical for the average user, with terms like "null object" and such. (The ordinary developer would probably just read it as "returning nil" here.)

Maybe something like...

You are seeing this deprecation message because you called `column_for_attribute` with the attribute
name "#{name}", which does not have a corresponding database column. In Rails 5.0, calling
`column_for_attribute` with a non-existent column name will return a special column object instead of
`nil`. If you are using this method to check for an attribute's existence, you should use
`attribute_exists?` instead.

It could be done in a separate PR though. @sgrif does that seem good to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't we referred to the null object pattern elsewhere (e.g. NullRelation)? That seems fine, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general principle, I think we should aim to require the least amount technical literacy required to comprehend these messages, because people need to understand them to take action (when I added this message @jeremy made me add an example of "circular reference").

In this case though, my main concern is that "return a null object" sounds too similar to "returning nil", so it might be extra confusing in this context :)

chancancode added a commit that referenced this pull request Jun 29, 2014
Don't encourage usage of `columns_hash`
@chancancode chancancode merged commit 374958b into rails:master Jun 29, 2014
@sgrif sgrif deleted the sg-attribute-exists branch March 14, 2018 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants