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
  • Has Many

Has Many · Changes

Page history
Updated Has Many (markdown) authored Aug 18, 2019 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Has-Many.md
View page @ ce56139f
> Finally my database won't have those pointless join tables. This is one of my most-wanted features. > Finally my database won't have those pointless join tables. This is one of my most-wanted features.
Has many connected through an array. PostgreSQL allows us to use arrays, Rails also allows us to use arrays, but why we have never been able to use them on associations. Well, honestly it was a bit hard to develop this feature, but the magic that it can do worth it. The idea is simple, one table stores all the ids and the other one says that `has many` records on that table because its records ids exist in the column of the array. Like: `Tag has many Videos connected through an array`. [PostgreSQL Docs](https://www.postgresql.org/docs/9.6/arrays.html) Has many connected through an array. PostgreSQL allows us to use arrays, Rails also allows us to use arrays, but why we have never been able to use them on associations. Well, honestly it was a bit hard to develop this feature, but the magic that it can do worth it.
The idea is simple, one table stores all the ids and the other one says that `has many` records on that table because its records ids exist in the column of the array. Like: `Tag has many Videos connected through an array`. [PostgreSQL Docs](https://www.postgresql.org/docs/9.6/arrays.html)
# How it works # How it works
...@@ -33,4 +35,6 @@ end ...@@ -33,4 +35,6 @@ end
All the original features from the `has_many` association are available, preloading inclusive. You can check the methods on the [Associations Docs](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html) from Rails. All the original features from the `has_many` association are available, preloading inclusive. You can check the methods on the [Associations Docs](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html) from Rails.
**One important notice** is that polymorphic is not allowed for array-like associations, because the tuples can be guaranteed every time.
There's no extra or additional provided method, only some for metaprogramming if necessary. There's no extra or additional provided method, only some for metaprogramming if necessary.
\ No newline at end of file
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