SailsJS - Waterline - Many to Many Database Table

96 Views Asked by At

I've joined an existing project where we use SailsJS and Waterline for our ORM. I've noticed the following database table : category_items__item_categories but I don't see any model for it.

Here's the actual models:

Item.JS

Item.JS
module.exports = {

    attributes: {
        name: {
            type: 'string'
        },
        description: {
            type: 'string',
            allowNull: true
        },
        categories: {
            collection: 'category',
            via: 'items',
        },
    }
}

Category.JS

module.exports = {

    attributes: {
        name: {
            type: 'string'
        },
        description: {
            type: 'string',
            allowNull: true
        },
        items: {
            collection: 'item',
            via: 'categories',
        },
    }
}

Does SailsJS generate tables at all? does it generate many to many tables? If not , how does it represent many to many relationship in the data store (in this case PostgreSQL database)?

Thanks!

1

There are 1 best solutions below

1
NeoNexus DeMortis On

Yes, Sails does generate its own join tables, if you don't provide your own "through" model. See this answer to see how to create your own "through" model: SailsJS - Waterline - add column to many to many relationship