loopback 4
node 10.14.2
npm 6.4.1
win10
I have a pre existing mongo db database containing all lower case collections. The scaffolding used in tutorial examples assumes a Proper Case collection. I would like to use a lowercase collection name, from Todo > todo
The collection appearas as Todo in mongo following the example given
I want to the model, controller and repository use the lowercase name of todo and not Todo..
@model decorator when the model name is different from the table name@property decorator when the property name is different from the column name._Note: This sample repo https://github.com/dhmlau/loopback4-example-todo-customized can be used as a reference._
Things to be discussed:
@johntom Please reference to this issue https://github.com/strongloop/loopback-next/issues/2134 and https://github.com/strongloop/loopback/issues/4086#issuecomment-445015678
@model({
settings: {
postgresql: { // replace postgresql with mongo or mongodb I think
table: 'customer',
},
},
})
Thanks, that did it!
@model({
settings: {
mongodb: {
collection: 'todo',
}
},
}) export class Todo extends Entity {
@property({
type: 'string',
id: true,
})
id?: string;
@property({
type: 'string',
required: true,
})
title: string;
@property({
type: 'string'
})
desc?: string;
@property({
type: 'boolean',
})
isComplete?: boolean;
constructor(data?: Partial<Todo>) {
super(data);
}
}
Let's improve our documentation to make it easier for future users to find how to customize database table names. I am going to reopen this issue and label it as "Docs".
Any volunteers to contribute this documentation improvement?
Hello @bajtos. I would like to help on this.
Any suggestion on which doc/code parts should I change? I'm thinking of the followings as starting points:
Another concern is that, it is the fact that settings in LB4 model decoration is different to LB3 model definition (which is options - https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#data-source-specific-options). I'm not sure whether settings vs options is the only difference, do we need to rewrite the model document to clarify which properties from LB3 are supported/not-supported in LB4?
I'm thinking of the followings as starting points:
Sounds good to me :+1:
Another concern is that, it is the fact that
settingsin LB4 model decoration is different to LB3 model definition (which isoptions- https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#data-source-specific-options). I'm not sure whethersettings vs optionsis the only difference,
This can be confusing. Under the hood, loopback-datasource-juggler is (and always has been) using the name settings, I am not sure why we renamed it to options in LB3. To my best knowledge, this is the only difference between LB3 and LB4.
do we need to rewrite the model document to clarify which properties from LB3 are supported/not-supported in LB4?
It would be great to have documentation on model settings (options) in LB4 section of our doc site, but I see how that can be more work that you may be willing to contribute. As a quick improvement, maybe it's enough to add a link pointing readers of LB4 docs to the LB3 doc page describing model settings?
@johntom Please reference to this issue #2134 and https://github.com/strongloop/loopback/issues/4086#issuecomment-445015678
@model({ settings: { postgresql: { // replace postgresql with mongo or mongodb I think table: 'customer', }, }, })
doesn't work for me.
this is my model snippets
@model({
settings: {
postgresql: {
table: 'offline_class',
},
},
})
and the package that i used
"@loopback/repository": "^1.5.5",
@johntom Please reference to this issue #2134 and https://github.com/strongloop/loopback/issues/4086#issuecomment-445015678
@model({ settings: { postgresql: { // replace postgresql with mongo or mongodb I think table: 'customer', }, }, })doesn't work for me.
this is my model snippets
@model({ settings: { postgresql: { table: 'offline_class', }, }, })and the package that i used
"@loopback/repository": "^1.5.5",
forget to rebuild.
it works now.
Most helpful comment
Thanks, that did it!