2013-08-22 10 views
10

C'è un modo per fare il mapping delle relazioni tra i modelli in Sails.js?Sails.js - Mappatura da uno a molti

Ecco quello che vorrei:

Video.js:

module.exports = { 

    attributes: { 

    filename: 'STRING', 
    length: 'INTEGER', 
    watchCount: 'INTEGER', 
    extension: 'STRING' 
    user: // I wan to reference to my User.js model 
    } 

}; 

E nei miei user.js:

module.exports = { 

    attributes: { 

    username: { 
     type: 'email', 
     required: true 
    }, 
    password: 'STRING', 
    videos: // I would like to have an array of videos after querying a user 

    } 

}; 

risposta

22

È possibile utilizzare le associazioni in sailsJs ora utilizzando il ramo v0.10 https://stackoverflow.com/a/21822843/1585332
La mappatura sarebbe qualcosa di simile ..

Video.js

module.exports = { 

    attributes: { 

    filename: 'STRING', 
    length: 'INTEGER', 
    watchCount: 'INTEGER', 
    extension: 'STRING' 
    user:{ 
     model: "user" 
    } 
    } 

}; 

user.js

module.exports = { 

    attributes: { 

    username: { 
     type: 'email', 
     required: true 
    }, 
    password: 'STRING', 
    videos:{ 
     collection: "video", 
     via: "user" 
    }, 

    } 

}; 
Problemi correlati