loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

How get the list of all the models an all method #5192

Closed fgvicente closed 3 years ago

fgvicente commented 4 years ago

Ok. in lb3...I get al model with this....

let models = app.models();

and I get all method for one model this...

let model = app.models[modelName]; let methods = model.sharedClass.methods()

my question... How would it be in lb4?

jannyHou commented 4 years ago

@fgvicente Models in LoopBack 4 describe the shape of data. Behavior like CRUD operations is added by repositories. This is different from LoopBack 3.x where models implement behavior too. You can check model and migrating models from LB3 to LB4 to understand more about the differences.

in lb3...I get all model with this.... let models = app.models();

In LB4 your models are usually defined in folder src/models, e.g. in application.ts file, you can import all model classes as

import * as models from './models';

The APIs are defined in repositories, see https://loopback.io/doc/en/lb4/Repositories.html

deepakrkris commented 4 years ago

@fgvicente all models are binded in the application context with prefix model., you can get a model with ctx.get('models.' + modelName). Please take a look at https://github.com/strongloop/loopback-next/pull/5378

raymondfeng commented 4 years ago

A better way is to use ctx.findByTag('model')

stale[bot] commented 3 years ago

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.