Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Latest commit

 

History

History
23 lines (20 loc) · 1.4 KB

Associations.md

File metadata and controls

23 lines (20 loc) · 1.4 KB

Associations

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.

IMPORTANT NOTE

In the examples used throughout the associations concepts guide, note that all references to Sails model classes are in lowercase. For example, in:

// User.js
module.exports = {
  connection: 'ourMySQL',
  attributes: {
    email: 'string',
    wishlist: {
      collection: 'product',
      via: 'wishlistedBy'
    }
  }
};

the collection key is set to product--this is the identity of the Sails model called Product. Whenever models are referenced in collection, via, model or through keys, their lowercased identity names should be used.