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, 2018 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Enum.md
View page @ 27d51e8c
...@@ -46,7 +46,7 @@ end ...@@ -46,7 +46,7 @@ end
### The type class ### The type class
Each enum type loaded from the database will have it's own class type of value, created under the [`enum.namespace`](https://github.com/crashtech/torque-postgresql/wiki/Enum#enum.namespace) namespace. Each enum type loaded from the database will have it's own class type of value, created under the [`enum.namespace`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.namespace) namespace.
```ruby ```ruby
Enum::Roles Enum::Roles
...@@ -68,7 +68,7 @@ Enum::Roles.admin.to_i # 2 ...@@ -68,7 +68,7 @@ Enum::Roles.admin.to_i # 2
### Models ### Models
If you kept the [`enum.initializer`](https://github.com/crashtech/torque-postgresql/wiki/Enum#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/Enum#enum.base_method). 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).
```ruby ```ruby
# models/user.rb # models/user.rb
class User < ActiveRecord::Base class User < ActiveRecord::Base
...@@ -100,14 +100,14 @@ user.role.manager? # true ...@@ -100,14 +100,14 @@ user.role.manager? # true
user.visitor? # false user.visitor? # false
``` ```
The `bang!` methods are controlled by the [`enum.save_on_bang`](https://github.com/crashtech/torque-postgresql/wiki/Enum#enum.save_on_bang): The `bang!` methods are controlled by the [`enum.save_on_bang`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.save_on_bang):
```ruby ```ruby
# The following will only perform a save on the database if enum.save_on_bang is set to true # The following will only perform a save on the database if enum.save_on_bang is set to true
user = User.new(role: :manager) user = User.new(role: :manager)
user.admin! user.admin!
``` ```
You can reach the I18n translations from three different ways, and the scopes are configured on [`enum.i18n_scopes`](https://github.com/crashtech/torque-postgresql/wiki/Enum#enum.i18n_scopes). On the third one, only the scopes on [`enum.i18n_type_scope`](https://github.com/crashtech/torque-postgresql/wiki/Enum#enum.i18n_type_scope) are used, that allows per-model customization. You can reach the I18n translations from three different ways, and the scopes are configured on [`enum.i18n_scopes`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.i18n_scopes). On the third one, only the scopes on [`enum.i18n_type_scope`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#enum.i18n_type_scope) are used, that allows per-model customization.
```ruby ```ruby
user = User.new(role: :manager) user = User.new(role: :manager)
user.role.text # User's manager user.role.text # User's manager
......
Clone repository
  • Wiki
  • Configuring

Data types

  • Enum
  • Interval

Querying

  • Distinct On
  • Auxiliary Statements