I have the following table:
| id | name | brothers |
|---|---|---|
| 1 | John | [3, 4] |
| 2 | Ben | [] |
| 3 | Mary | [1, 4] |
| 4 | Peter | [1, 3] |
How to set up a relation where I could get all brothers data in single query on single record? the brothers column is using Postgres Array type.
Right now I am using 2 queries, 1 to get John, and then query again to get brothers info based on his brothers IDs.
I found the following in Sequelize Docs:
Sequelize supports self-referential Many-to-Many relationships, intuitively:
Person.belongsToMany(Person, { as: 'Children', through: 'PersonChildren' })
// This will create the table PersonChildren which stores the ids of the objects.
But I couldn't get it work with:
People.belongsToMany(People, { as: 'Brothers', through: 'peopleBrothers', foreignKey: 'brothers' })
Can this be done?