Skip to content

Comments

Allow options for :enum and provide :nested option to create namespaced scopes and methods#13433

Closed
imanel wants to merge 1 commit intorails:masterfrom
imanel:nested_enums
Closed

Allow options for :enum and provide :nested option to create namespaced scopes and methods#13433
imanel wants to merge 1 commit intorails:masterfrom
imanel:nested_enums

Conversation

@imanel
Copy link
Contributor

@imanel imanel commented Dec 21, 2013

This one is related to #13389 and should solve problems (1), (2) and (3) by allowing to create namespaces in such cases.

What is provided by this pull request?

class Conversation < ActiveRecord::Base
  enum :status, [ :active, :archived ], nested: true
end

Conversation.status_active

conversation.status_active!
conversation.status_active? # => true
conversation.status  # => "active"
Conversation::STATUS # => { "active" => 0, "archived" => 1 }

Unfortunately I had to change API of enum from

class Conversation < ActiveRecord::Base
  enum status: [ :active, :archived ]
end

to:

class Conversation < ActiveRecord::Base
  enum :status, [ :active, :archived ]
end

to make sure that options are extracted. If anyone has idea how to implement it without changing API then I will be glad to modify this pull request, but we might also think about potential other options in future and try to change API now - it's up to community.

EDIT: I'm considering changing option from "nested" to "prefix", but I will gladly hear what community have to say.

@rafaelfranca
Copy link
Member

Agree with @dhh here db41eb8#commitcomment-4922983.

Thank you so muck for the contribution

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants