Loopback-next: hasOne and hasMany Relation don't Work lb4

Created on 4 Oct 2019  路  4Comments  路  Source: strongloop/loopback-next

Steps to reproduce

The examples in the documentation not work

Current Behavior

// add this line to register inclusion resolver
    this.registerInclusion('account', this.account.inclusionResolver);

when i add this line the registerInclusion is not reconozed

and supplierRepository.find({include: [{relation: 'account'}]});
this line show me an error :

/suppliers/2/accounts: 500 Error: Relation "account" is not defined for Supplier model

Expected Behavior

[
  {
    id: 1,
    name: 'Thor',
    account: {accountManager: 'Odin', supplierId: 1},
  },
  {
    id: 5,
    name: 'Loki',
    account: {accountManager: 'Frigga', supplierId: 5},
  },
];

Link to reproduction sandbox

Additional information

Related Issues

_See Reporting Issues for more tips on writing good issues_

bug

Most helpful comment

My old version:
```@loopback/cli version: 1.16.1

@loopback/* dependencies:

  • @loopback/authentication: ^2.1.1
  • @loopback/boot: ^1.4.0
  • @loopback/build: ^1.7.1
  • @loopback/context: ^1.19.0
  • @loopback/core: ^1.8.1
  • @loopback/metadata: ^1.2.1
  • @loopback/openapi-spec-builder: ^1.2.1
  • @loopback/openapi-v3-types: ^1.1.1
  • @loopback/openapi-v3: ^1.6.1
  • @loopback/repository-json-schema: ^1.6.1
  • @loopback/repository: ^1.6.1
  • @loopback/rest: ^1.15.0
  • @loopback/testlab: ^1.5.0
  • @loopback/docs: ^1.22.1
  • @loopback/example-hello-world: ^1.2.1
  • @loopback/example-log-extension: ^1.2.1
  • @loopback/example-rpc-server: ^1.2.1
  • @loopback/example-todo: ^1.6.1
  • @loopback/example-soap-calculator: ^1.6.2
  • @loopback/service-proxy: ^1.2.1
  • @loopback/http-caching-proxy: ^1.1.1
  • @loopback/http-server: ^1.4.0
  • @loopback/example-todo-list: ^1.7.1
  • @loopback/dist-util: ^0.4.0
  • @loopback/rest-explorer: ^1.2.1
  • @loopback/eslint-config: ^1.1.1
  • @loopback/tslint-config: ^2.1.0
  • @loopback/example-express-composition: ^1.4.1
  • @loopback/example-greeter-extension: ^1.3.1
  • @loopback/booter-lb3app: ^1.2.1
  • @loopback/example-lb3-application: ^1.1.1
  • @loopback/example-greeting-app: ^1.1.1
  • @loopback/example-context: ^1.2.1```

I executed npm update and problem resolved

All 4 comments

@agnes512 @nabdelgadir, it's related to the inclusion resolver. Could you please take a look? Thanks.

Hi @hevillalobosccxc. We made a mistake in the docs. the function name registerInclusion should be registerInclusionResolver. This has been fixed in this PR. The site will be updated in the near furture.

I solvented, the problem is that all packages in the package.json to loopback were too olds @agnes512 but in the documentation would be specific the version that this method registerInclusion work

My old version:
```@loopback/cli version: 1.16.1

@loopback/* dependencies:

  • @loopback/authentication: ^2.1.1
  • @loopback/boot: ^1.4.0
  • @loopback/build: ^1.7.1
  • @loopback/context: ^1.19.0
  • @loopback/core: ^1.8.1
  • @loopback/metadata: ^1.2.1
  • @loopback/openapi-spec-builder: ^1.2.1
  • @loopback/openapi-v3-types: ^1.1.1
  • @loopback/openapi-v3: ^1.6.1
  • @loopback/repository-json-schema: ^1.6.1
  • @loopback/repository: ^1.6.1
  • @loopback/rest: ^1.15.0
  • @loopback/testlab: ^1.5.0
  • @loopback/docs: ^1.22.1
  • @loopback/example-hello-world: ^1.2.1
  • @loopback/example-log-extension: ^1.2.1
  • @loopback/example-rpc-server: ^1.2.1
  • @loopback/example-todo: ^1.6.1
  • @loopback/example-soap-calculator: ^1.6.2
  • @loopback/service-proxy: ^1.2.1
  • @loopback/http-caching-proxy: ^1.1.1
  • @loopback/http-server: ^1.4.0
  • @loopback/example-todo-list: ^1.7.1
  • @loopback/dist-util: ^0.4.0
  • @loopback/rest-explorer: ^1.2.1
  • @loopback/eslint-config: ^1.1.1
  • @loopback/tslint-config: ^2.1.0
  • @loopback/example-express-composition: ^1.4.1
  • @loopback/example-greeter-extension: ^1.3.1
  • @loopback/booter-lb3app: ^1.2.1
  • @loopback/example-lb3-application: ^1.1.1
  • @loopback/example-greeting-app: ^1.1.1
  • @loopback/example-context: ^1.2.1```

I executed npm update and problem resolved

Was this page helpful?
0 / 5 - 0 ratings