... | @@ -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 |
|
|