Waterline.js加入/填充现有数据库 [英] Waterline.js Joins/Populate with existing database
问题描述
我有一个现有的postgres数据库,我正在使用该数据库来构建sails.js驱动的网站,并利用水线进行ORM.
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.
当使用非生产数据库时,我对waterline如何为我生成联接表感到满意,但是我真的不确定如何绕过它来与我拥有的当前表及其外键关系一起使用.为了让我对表的类型有个大概的了解,下面将显示一个示例:
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 |
因此,在上表中,我通常可以加入英特尔->联盟和英特尔-> Planet并访问每个数据库中的数据.
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.
在我的Intel,Alliance,Planet等高线模型中,我需要什么才能轻松访问它?
What would I need in my waterline model of Intel, Alliance, Planet to access this easily?
我想做一个:
Intel.find({alliance.name= 'test'})
或
Intel.find().populate('planet')
然后可以通过某种方式访问intel.planet.score或intel.alliance.name等
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.
推荐答案
first create models for all your databases table , as mention here you can populate models and return joins results
这篇关于Waterline.js加入/填充现有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!