javascript - SailsJS Many to Many - Some objects in a controller -


i post here , because start development project sails , mongodb 3.0.2.

i beginner framework , orm (aka waterline).

in project i've 2 classes : listeners , titles, , need relations :

  • n listeners can add favorite n titles -> many many.

this sample of classes :

listeners :

module.exports = {  	schema	  : true,    autopk    : false,    attributes: {      name : {       	type: 'string' ,        required : true,        string : true,        notnull:true      },        email : {       	type: 'email' ,        required : true,        email :true,        notnull:true,        unique: true,        primarykey:true      },        password : {       	type: 'string',        required : true,        string:true,        minlength : 6,        notnull:true      },        favorites:{        collection :"title",        via : "bookmarkedby",        dominant: true      }    //....     addfavoritetitle:function(userid,titleid,callback){      user.findone(userid).exec(function(error, user) {       if(!error && user){              user.favorites.add(titleid);        user.save(function(error) {});        callback(error,user);      }  else{       callback(error,user);     }     });    },  }

titles :

module.exports = {  	schema	  : true,  	autopk : false,  	attributes: {    		title : {   	    	type: 'string',  	    	required : true,  		    //string : true,  		    notnull:true,   		    unique : true,  		    primarykey:true  	    },    	    artist : {   	    	type: 'string',  	    	required : true,  		    string : true,  		    notnull:true  	    },    	    artwork : {   	    	type: 'string'  	    },  	    playing:{  	    	type:'boolean',  	    	defaultsto:false  	    },  	    bookmarkedby:{  	    	collection : "user",  	    	via :  "favorites"  	    },  	},      //.....         }

i followed official documention of sails, don't see / undestand :

how recover information on title information contained in relationship: " favorites" of user class .

and how relationship " bookmarkedby " class title , find / access information on user has title in "favorites".

so, fail use relationship between 2 classes , according documentation.

can me ?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -