loopbackio / loopbackio/loopback-next

Confusing @model() syntax

Open
#2,142 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

developer-experience feature good first issue help wanted
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

In LB3, users could specify model settings at two levels: as a root property or inside options property.

See https://stackoverflow.com/q/53307168/69868 for an example of LB3 syntax applied in an LB4 project:

@model({
  settings: {strict: false},
  name: 'client',
  plural: 'clients',
  options: {
    mongodb: {
      collection: 'clients',
    },
  },
})
export class Client extends Entity {
  // ...
}

I am proposing to make two changes in LB4 to help users coming from LB3:

  1. Recognize options the same way as settings. In the example above, mongodb settings are not picked by LB4 now. With the proposed change in place, LB4 will set collection to clients as expected. Alternatively, tell the user setting options that they are trying to set an unsupported model-definition property. This can be done at compiler level too.

  2. Allow settings to be provided as top-level properties, for example:

    @model({
      name: 'client',
      strict: false,
      mongodb: {
        collection: 'clients',
      },
    })
    export class Client extends Entity {
      // ...
    }
    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the @model() decorator and trace how LB4 reads model settings, comparing that behavior with the LB3 examples in the issue. Resolve whether options should be accepted or rejected and whether top-level settings should be supported; done means the chosen behavior is implemented and verified for the Client examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.