1

I have an existing postgres database which I am using to build a sails.js driven website, utilising waterline for ORM.

I'm fine with using my database in its existing form for everything other than population i.e. joining tables.

When working with a non-production database I'm comfortable with how waterline can produce join tables for me, but I'm really unsure how to bypass this to work with the current tables I have and their foreign key relationships. To give an idea of the types of tables I would typically have I've shown an example below:

| Intel       |        |
|-------------|--------|
| Column      | Type   |
| id          | int PK |
| alliance_id | int FK |
| planet_id   | int FK |
| dist        | int    |
| bg          | string |
| amps        | int    |


| Alliance |        |
|----------|--------|
| Column   | Type   |
| id       | int PK |
| name     | string |
| score    | int    |
| value    | int    |
| size     | int    |


| Planet    |        |
|-----------|--------|
| Column    | Type   |
| id        | int PK |
| rulerName | string |
| score     | int    |
| value     | int    |
| size      | int    |

So in the above tables I would typically be able to join Intel --> Alliance and Intel --> Planet and access the data across each of these.

What would I need in my waterline model of Intel, Alliance, Planet to access this easily?

I'd love to do a:

Intel.find({alliance.name= 'test'})

or

Intel.find().populate('planet')

and then somehow be able to access intel.planet.score or intel.alliance.name etc

Thanks for any help. I can add more information if required just let me know in the comments.

munkee
  • 759
  • 1
  • 9
  • 23

1 Answers1

0

first create models for all your databases table , as mention here you can populate models and return joins results

Community
  • 1
  • 1
Ahmed farag mostafa
  • 2,802
  • 2
  • 14
  • 33
  • That example looks like a single table join. I have a junction table in my current DB so I would need to populate through that – munkee Jun 15 '16 at 12:50