The problem is the following: I have a database and schema designed in MySql, and I'm trying to import automaticaly to my api base in LoopBack the models to work with them. I have read the following help: http://loopback.io/doc/en/lb2/Discovering-models-from-relational-databases.html#additional-discovery-functions But It doesn't work.
I have tried, changing the INVENTORY for datalogger (name of table in my database.
var loopback = require('loopback');
var ds = loopback.createDataSource('mysql', {
"host": "localhost",
"port": 3306,
"database": "maintenancetooldb",
"username": "root",
"password": "Password_4567"
});
// Discover and build models from INVENTORY table
ds.discoverAndBuildModels('datalogger', {visited: {}, associations: true},
function (err, models) {
console.log(JSON.stringify(inv, null, 2));
// Now we have a list of models keyed by the model name
// Find the first record from the inventory
models.datalogger.findOne({}, function (err, inv) {
if(err) {
console.error(err);
console.log(JSON.stringify(inv, null, 2));
return;
}
console.log("\nInventory: ", inv);
// Navigate to the product model
// Assumes inventory table has a foreign key relationship to product table
inv.product(function (err, prod) {
console.log("\nProduct: ", prod);
console.log("\n ------------- ");
});
});
});
To be honest I'm lost, yesterday I used sequelize-auto for the first time, but today the requirements have been changed.
Thanks in advance for you help.