Skip to content

app.model should report unknown options #169

Closed

Description

@bajtos

Consider the following code:

var User = app.model('User', {
  options: { base: 'User' },
  relations: {
    accessTokens: {
      model: "AccessToken",
      type: "hasMany",
      foreignKey: "userId"
    }
  },
  dataSource: 'Memory'
});

LoopBack happily ignores relations property and creates a User model without relations. The problem manifests with a mysterious crash of the application much later:

server/node_modules/loopback/lib/models/user.js:160
          user.accessTokens.create({
                            ^
TypeError: Cannot call method 'create' of undefined
    at server/node_modules/loopback/lib/models/user.js:160:29
    at server/node_modules/loopback/lib/models/user.js:224:7
    at server/node_modules/loopback/node_modules/bcryptjs/bcrypt.min.js:40:101
    [cut]

Proposal

app.model and app.dataSource should throw an error when the configuration contains unknown properties.

Activity

  1. ritch commented on Feb 5, 2014

    @ritch
    Member

    Your proposal sounds good. Configs should be validated in the workspace as well.

  2. self-assigned this
    on Feb 28, 2014
  3. added this to the milestone on Feb 28, 2014
  4. modified the milestone: #Rel lb 2.0.0 on Sep 30, 2014
  5. bajtos commented on Oct 15, 2014

    @bajtos
    MemberAuthor

    FWIW, the example above no longer crashes, because all options can be defined on the top level too.

    Adding a custom option is a valid usage, e.g. connectors use that for database-specific configuration.

    I am closing this issue as no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions