woss
woss

Reputation: 1003

Mapping two models in a relation with waterline

Did someone had experience with mapping 2 models with sails.js? I think it would be easier to give example:

Application has many configurations, i would like to map them with relation of appUUID or unique MongoDB id with configurations.

I couldn't find how to do it on waterline(ORM for sails.js) github docs, that's the reason why i am asking this.

Thank you in advance.

Upvotes: 3

Views: 3092

Answers (2)

Muhammad Ashir
Muhammad Ashir

Reputation: 56

use Collection block in attributes for relationship

  • if relation is one to one don't need any collection
  • if relation is one to many need write one collection
  • if relation is many to many need to write two collection

example of one to many:

at the side of one:

attributes:{
   userName:'string',
   password:'string',
   abc:{
       collection:'manySideTable',
       via:'xyz'
    }
 }

at the side of many

attributes:{
       userName:'string',
       password:'string',
       xyz:{
           collection:'oneSideTable',
           columnName:'FK'
        }
     }

Upvotes: 1

JRMLSTF
JRMLSTF

Reputation: 85

Associations are officially Supported in Waterline

Overview

From the docs:

With Sails and Waterline, you can associate models across multiple data stores. This means that even if your users live in PostgreSQL and their photos live in MongoDB, you can interact with the data as if they lived together in the same database. You can also have associations that span different connections (i.e. datastores/databases) using the same adapter. This comes in handy if, for example, your app needs to access/update legacy recipe data stored in a MySQL database in your company's data center, but also store/retrieve ingredient data from a brand new MySQL database in the cloud.

Supported Association Types

Planned Association Types


Original Post

This is in progress, see the issue #124 on the Github. There is also a branch on the Waterline Github repo

Upvotes: 2

Related Questions