database - Foreign key constraint on SailsJS -


this college model

module.exports = {    attributes: {       name:{         type:'string',         required:true       },       location:{             type:'string',             required:true         },         faculties:{             collection:'faculty',             via:'college'         }   } }; 

this faculty model

module.exports = {    attributes: {         name:{             type:'string',             required:true         },         description:{             type:'string'         },         college:{             model:'college',         required:true         }         ,         years:{             collection:'year',             via:'faculty'         }   } }; 

my problem can add new faculty value in college attribute. if don't have college 3000 id, can still add college attribute won't show when list faculties. how can prevent adding faculty invalid college id?

currently waterline not create foreign key constraints in manner describe. creates associated field.

you can use different library instead of waterline such sequelize.js here link how go doing that

https://groups.google.com/forum/#!topic/sailsjs/almxbkfncio

if using sql database can manally create foreign key constraint yourself.

or can validate value of college before being set in faculty model checking in beforevalidate() or aftervalidate() on faculty model.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -