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
  • Inherited Tables

Inherited Tables · Changes

Page history
Updated Inherited Tables (markdown) authored Aug 18, 2018 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Inherited-Tables.md
View page @ ed5b60ad
...@@ -46,6 +46,22 @@ class ActivityPost < Activity ...@@ -46,6 +46,22 @@ class ActivityPost < Activity
end end
``` ```
#### Table name to Model name
Since the data that indicates the record type is a table name, this process rely on rails common translation from class name to table name. But this is tricky, because `activity_posts` can either be `ActivityPost` or `Activity::Post` (or even another model using `self.table_name = "activity_posts"`). This GEM try its best to translate the table name to a model name, chicking all the possibilities, so you might not face issues. **But**, you can always help it, and make the process more accurate or even faster.
Please, check the [Configuration Page](https://github.com/crashtech/torque-postgresql/wiki/Configuring) in order to see the options to improve this operation.
The most important setting is the [`irregular_models`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#irregular_models), which can both help descibing the correct relationship between a table name and a model name, and improve the performance by avoinding the default behavior of searching for the model based on the table name. Although the table name once associated with an model name is cahced, be aware of this for setting irregular names.
```ruby
Torque::PostgreSQL.configure do |c|
c.irregular_models = {
'my_awesome_table_name' => 'SimpleModel'
}
end
```
### Querying ### Querying
#### Single record #### Single record
...@@ -113,20 +129,4 @@ list.second._record_class # "activity_posts" ...@@ -113,20 +129,4 @@ list.second._record_class # "activity_posts"
list.third._record_class # "activity_books" list.third._record_class # "activity_books"
``` ```
This will be improved in the next `v0.2.1` to accept an `type_activity?`. This will be improved in the next `v0.2.1` to accept an `type_activity?`.
\ No newline at end of file
#### Table name to Model name
Since the data that indicates the record type is a table name, this process rely on rails common translation from class name to table name. But this is tricky, because `activity_posts` can either be `ActivityPost` or `Activity::Post` (or even another model using `self.table_name = "activity_posts"`). This GEM try its best to translate the table name to a model name, chicking all the possibilities, so you might not face issues. **But**, you can always help it, and make the process more accurate or even faster.
Please, check the [Configuration Page](https://github.com/crashtech/torque-postgresql/wiki/Configuring) in order to see the options to improve this operation.
The most important setting is the [`irregular_models`](https://github.com/crashtech/torque-postgresql/wiki/Configuring#irregular_models), which can both help descibing the correct relationship between a table name and a model name, and improve the performance by avoinding the default behavior of searching for the model based on the table name. Although the table name once associated with an model name is cahced, be aware of this for setting irregular names.
```ruby
Torque::PostgreSQL.configure do |c|
c.irregular_models = {
'my_awesome_table_name' => 'SimpleModel'
}
end
```
\ No newline at end of file
Clone repository
  • Wiki
  • Configuring

Data types

  • Enum
  • Interval

Querying

  • Dynamic Attributes
  • Distinct On
  • Auxiliary Statements
  • Inherited Tables