javascript - How to add another field in a join sails js -


hey getting started sails js , mongodb , im bit confused.

i have 2 models many-to-many relationship:

user.js

module.exports = {   attributes: {     username: 'string',     password: 'string',     doors:{         collection: 'door',         via: 'users',     }   } }; 

and door.js

module.exports = {   attributes: {     name: 'string',     users:{         collection: 'user',         via: 'doors'     }   } }; 

this works fine, can create user , door , associate 1 other. i'd have field in join, expiry date (say user can have access particular door until particular date).

how go doing that?

you need create many many through association. not officially supported of yet.

you can manually however.

now, in example may a little more difficult doors user , vice versa, because have preform second up. can following setup:

userdoors     .find()     .where({expires:{'<':new date()}})     .populate('doors')     .populate('users')     .exec(/*....*/) 

your models

user.js  module.exports = {   attributes: {     username: 'string',     password: 'string',     doors:{         collection: 'userdoors',         via: 'users',     }   } };   userdoors.js module.exports = {   attributes: {     doors:{         model: 'door'     },     users:{         model: 'user'     },     expires: 'datetime'      } };    , door.js  module.exports = {   attributes: {     name: 'string',     users:{         collection: 'userdoors',         via: 'doors'     }   } }; 

do google search sails.js many many through find looking for.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -