enum naming conflict solved by adding name of enum as prefix #14346

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants

jaxi commented Mar 11, 2014

class Book < ActiveRecord::Base
  enum status: [:dispatch, :delivering, :sent]
  enum refund: {dispatch: 0, delivering: 2, sent: 3}
end

Considering this kind of situation, if calling @book.dispatch?, Rails will only show whether book refunding is dispatched or not, since dispatch? method has been overwritten. This kind of naming conflict sometimes might cause misunderstanding.

My solution is simply adding enum name as the prefix, so we can know both of the status and refunding status by calling @book.status_dispatch? and @book.refund_dispatch?.

Owner

rafaelfranca commented Mar 11, 2014

Just to point out this feature was already suggested and rejected #13433 and db41eb8#commitcomment-4922983.

I still think this is not needed. Adding prefix always as you did will make harder to users who don't have conflicts in they enums. Adding this feature optionally will add more complexity to our code than is worth.

But this is a recurring request so I think is better to hear more thoughts about it.

@senny @dhh @chancancode what do you think?

Owner

rafaelfranca commented Mar 11, 2014

@jaxi forgot to say, thank you so much for the pull request, we really appreciate.

Member

chancancode commented Mar 11, 2014

Just wanted to quickly point out that this would raise an ArgumentError on 4.1.0.rc1 instead of failing silently

Owner

dhh commented Mar 11, 2014

My opinion remains unchanged from the earlier conversations on this.

dhh closed this Mar 11, 2014

senny added the enum label Sep 4, 2014

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