Friday, 19 May 2017

Sails.js many-to-many through with the same model

There is plenty of answers on stackoverflow on how to use a many-to-many relationships to describe a relationship of one model with itself but apparently I can't find a way to do the same with a Through table.

I've tried the very simplest idea:

//Document.js

{ attributes: {
    similarDocuments: {
        collection: 'document',
        via: 'similarDocument',
        through: 'similardocument'
    }
}}

// SimilarDocument.js

{ attributes: {
    document: {
        model: 'document',
        primaryKey: true
    },
    similarDocument: {
        model: 'document',
        primaryKey: true
    }
}}

But apparently it doesn't work. Any idea?



via heapOverflow

No comments:

Post a Comment