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 Apr 01, 2022 by Carlos's avatar Carlos
Show whitespace changes
Inline Side-by-side
Enum.md
View page @ ebb31868
......@@ -11,12 +11,15 @@ create_enum :roles, %i(visitor manager admin)
Some other examples are:
```ruby
# Only for Rails < 7.0
# ['status_foo', 'status_bar']
create_enum :status, %i(foo bar), prefix: true
# 'foo_tst', 'bar_tst']
create_enum :status, %i(foo bar), suffix: 'tst'
```
> NOTE: The `create_enum` method now exists on Rails, so it was removed from the gem, preventing the use of prefix and suffix. However, the `add_enum_values` still exists only in this gem.
You can also manage this type along other migrations, renaming, adding values, or deleting it.
```ruby
# Rename enum by renaming the type it represents
......@@ -39,8 +42,9 @@ Once you've created the type, you can use it while creating your table in three
create_table :users do |t|
t.string :name
t.role :role # Uses the type of the column, since enum is a type
t.enum :status # Figures the type name from the column name
t.enum :last_status, subtype: :status # Explicit tells the type to be used
t.enum :status # Figures the type name from the column name !! ONLY RAILS < 7.0
t.enum :last_status, subtype: :status # Explicit tells the type to be used !! ONLY RAILS < 7.0
t.enum :last_status, enum_type: :status # This is the official Rails 7.0 syntax !! ONLY RAILS >= 7.0
end
```
......@@ -93,7 +97,7 @@ You have to go to each of your models and enable the functionality for each enum
```ruby
# models/user.rb
class User < ActiveRecord::Base
enum :role, :status
torque_enum :role, :status
end
```
......
Clone repository
  • Wiki
  • Configuring

Data types

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

Querying

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