Reputation: 431
hello guys i m new to loopback and i go through all document but haven't find any solution related to my problem as describe below 1. is it possible to change table name for eg:-
var mysqlDs = app.dataSources.mysqlDs;
function createCoffeeShops(cb) {
mysqlDs.automigrate('CoffeeShop', function(err) {
if (err) return cb(err);
var CoffeeShop = app.models.CoffeeShop;
CoffeeShop.create([{
name: 'Bel Cafe',
city: 'Vancouver',
}, {
name: 'Three Bees Coffee House',
city: 'San Mateo',
}, {
name: 'Caffe Artigiano',
city: 'Vancouver',
}], cb);
});
this code i found in official document of loopback.io and my model name is CoffeeShop now here is my question how i can automigrate with different table name of eg :- mysqlDs.automigrate('CoffeeShop'// i want this name as employee is this thing is not possible or i missing something 2.second thing how i can create controller for eg:- suppose my folder structure is like this
1.client 2.common 3.server now i want to create new folder name like controller and here i want to place my all business logic now my question is that how i can link this file to my model and all other required file overall during execution this file should also execute is these thing possible in loopback
Upvotes: 0
Views: 60
Reputation: 3728
It looks like you are using MySQL. Apply the following to your CoffeeShop
definition to use the table name employee
.
{
"name": "CoffeeShop",
"options": {
"mysql": {
"table": "employee"
}
},
...
}
This is documented in Model definition JSON file.
I'd recommend keeping with LoopBack's recommended directories until you gain more experience with the framework. If you really want to place models in a folder named controller
, you'll want to look into the server/model-config.json
file. At the top, you'll see a section for _meta.sources
. You can add your new folder here and begin putting models in that folder.
{
"_meta": {
"sources": [
...,
"../controller"
]
}
}
Upvotes: 1