Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: how to configure a custom table/collection name different from model class name #2197

Closed
2 tasks
johntom opened this issue Dec 26, 2018 · 8 comments · Fixed by #5998
Closed
2 tasks

Comments

@johntom
Copy link

johntom commented Dec 26, 2018

Description / Steps to reproduce

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

Current Behavior

The collection appearas as Todo in mongo following the example given

Expected Behavior

I want to the model, controller and repository use the lowercase name of todo and not Todo..

Acceptance Criteria (Added by LoopBack team)

  • Add content on how to configure the @model decorator when the model name is different from the table name
  • Add content on how to configure the @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:

@haotangio
Copy link
Contributor

@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',
    },
  },
})

@johntom
Copy link
Author

johntom commented Dec 30, 2018

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);
  }
}

@johntom johntom closed this as completed Dec 30, 2018
@bajtos
Copy link
Member

bajtos commented Jan 11, 2019

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".

@bajtos bajtos reopened this Jan 11, 2019
@bajtos bajtos changed the title lowercase collection names in mongo Docs: how to configure a custom table/collection name different from model class name Jan 11, 2019
@bajtos
Copy link
Member

bajtos commented Jan 11, 2019

Any volunteers to contribute this documentation improvement?

@haotangio
Copy link
Contributor

haotangio commented Jan 14, 2019

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?

@dhmlau dhmlau added the TOB label Jan 22, 2019
@bajtos
Copy link
Member

bajtos commented Jan 24, 2019

I'm thinking of the followings as starting points:

Sounds good to me 👍

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,

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?

@leotj

This comment has been minimized.

@leotj

This comment has been minimized.

@dhmlau dhmlau added 2020Q3 and removed TOB labels Apr 16, 2020
@agnes512 agnes512 mentioned this issue Jun 9, 2020
7 tasks
@dhmlau dhmlau added this to the Jul 2020 milestone Jun 16, 2020
@dhmlau dhmlau removed this from the Jul 2020 milestone Jun 27, 2020
@agnes512 agnes512 self-assigned this Jul 21, 2020
@agnes512 agnes512 mentioned this issue Jul 23, 2020
7 tasks
@agnes512 agnes512 added this to the Jul 2020 milestone Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants