Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Wiki
  • Enum

Enum · Changes

Page history
Updated Enum (markdown) authored Aug 18, 2019 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Enum.md
View page @ 7f7b84b2
......@@ -62,13 +62,13 @@ Enum::Roles.each do |role|
end
# You can use index-based references of a value
Enum::Roles.new(0) # #<Enum::Roles "visitor">
Enum::Roles.new(0) # :visitor
Enum::Roles.admin.to_i # 2
```
### Models
If you kept the [`enum.initializer`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.initializer) setting as `false`, you have to go to each of your models and enable the functionality for each enum-type field. You don't need to provide the values since they will be loaded from the database. The method name is defined on [`enum.base_method`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.base_method).
You have to go to each of your models and enable the functionality for each enum-type field. You don't need to provide the values since they will be loaded from the database. The method name is defined on [`enum.base_method`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.base_method).
```ruby
# models/user.rb
class User < ActiveRecord::Base
......@@ -84,9 +84,9 @@ User.roles
You can set the column value from `String`, `Symbol`, and `Integer`:
```ruby
user = User.new
user.role = 'admin' # #<Enum::Roles "admin">
user.role = :manager # #<Enum::Roles "manager">
user.role = 0 # #<Enum::Roles "visitor">
user.role = 'admin' # :admin
user.role = :manager # :manager
user.role = 0 # :visitor
```
This allows you to compare values, or make questions about it:
......
Clone repository
  • Wiki
  • Configuring

Core Extensions

  • Range

Data types

  • Enum
  • Enum Set
  • Interval
  • Date/Time Range
  • Box
  • Circle
  • Line
  • Segment

Querying

  • Arel
  • Has Many
  • Belongs to Many
  • Dynamic Attributes
  • Distinct On
  • Auxiliary Statements
  • Inherited Tables