Do you know what settlement is? it to include the entire linked object when loading from the database. In fact, this is the connection that you are trying to make, if all you need is a row search than querying a table without filling, both functions that you created will do.
It seems to me that you are rewriting how Sails made the connection. Id suggests giving Associates documents another read in the Sails Documentation: Associations . Since, depending on your case, you are simply trying to establish a one-to-many relationship with each table, you can avoid the middle table in my guess, but in order to better understand the identifier, you need to understand your use case.
When I saw the mySQL code, it seemed to me that you are still thinking in MySQL and PHP that it takes time to convert from :), forcing the joins and middle tables themselves to redo many sails that are automatic for you. I redid your example on the "disk" adapter and it worked perfectly. The whole point of WaterlineORM is to abstract the level of transition to SQL, if absolutely necessary.
Here is what I would do for your example: first, without SQL, only create models on the drive adapter ID:
// Lang.js attributes: { id :{ type: "Integer" , autoIncrement : true, primaryKey: true }, code :"string" }
Do you see what I did in abundance here? I don't need the Id part, as Sails does this for me. Just an example.
// Meta.js attributes: { code :"string" }
it's better:)?
// MetaLang.js attributes: { title : "string", desc : "string", meta_id : { model : "meta", }, lang_id : { model : "lang", } }
Now, just by creating the same values as in your example, I run the sail console type:
MetaLang.find({meta_id : 1 ,lang_id:2}).exec(function(er,res){ console.log(res); });
Exit →>
sails> [ { meta_id: 1, lang_id: 2, title: 'My blog', id: 2 } ]
Now, if you want to display metafiles with identifier 1 and what is lang with id 2, we use populate, but the link to connect / search is as simple as this.
sails> Meta_lang.find({meta_id : 1 ,lang_id:2}).populate('lang_id').populate('meta_id').exec(function(er,res){ console.log(res); }); undefined sails> [ { meta_id: { code: 'default', id: 1 }, lang_id: { code: 'En', id: 2 }, title: 'My blog', id: 2 } ]
At this point, id switches the adapters to MySQL, and then creates the MySQL tables with the same column names as above. Create FK_constraints and voila.
Another strict policy you can add is to set up an end-to-end and dominant role for each model. You can learn more about this in the documentation of the Association, and it depends on the nature of the association (many-to-many, etc.).
To get the same result without knowing the identifiers in front of you:
sails> Meta.findOne({code : "default"}).exec(function(err,needed_meta){ ..... Lang.findOne({code : "En"}).exec(function(err_lang,needed_lang){ ....... Meta_lang.find({meta_id : needed_meta.id , lang_id : needed_lang.id}).exec(function(err_all,result){ ......... console.log(result);}); ....... }); ..... }); undefined sails> [ { meta_id: 1, lang_id: 2, title: 'My blog', id: 2 } ]