-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Include related models in "GET /mymodels" results #1889
Comments
@GuillaumeJasmin, it seems to be working with:
not (please note the quotes around the param name):
Then it comes to the question that whether the param name should be wrapped around the quotes. I'll get back to you on that. Hope it will get you going first. Another way to test (which I usually do) is to use the API Explorer, which can be found at:
|
@GuillaumeJasmin, talked to @raymondfeng and it looked like a bug that the quotes are needed for param name. Marking it as |
@GuillaumeJasmin the include functionality is not yet implemented.
The expect behavior is to return for each todo lists the list of todos, but nothing is returned. |
@dhmlau Thanks for your answer, however this doesn't work, and as @mrbatista say, it seems not implemented. I don't understand the last release of Loopback. But it seems that Loopback 4 is more complicated and not ready for production. I understand the vision of LB4 to have a small core system, and the rest as extension. It's seems powerful. But the migration between LB3 and LB4 is too complicated. For example, why do not provide a set of extensions in order to keep the simplicity of LB3, without the needed to create repository, controller for default CRUD actions (only if we need custom actions) ? I dropped my last back-end frameworks for Loopback since few years with a single motivation: simplicity. But it seems not to be the case with LB4. It's maybe more extensible, but need hard work, and the simplicity is not still here. I know it's not the best place to tell that, but this issue is one more lack of functionality on LB4 compare to LB3. I have to stop trying to work on LB4. Maybe I forget a thing, or I don't understand the future of Loopback ? |
This is a missing feature indeed, I am relabeling the issue. @GuillaumeJasmin thank you for writing down your concerns and feelings about LoopBack 4. We are fully aware of the gap in feature parity between LoopBack 3 and LoopBack 4 and that LB4 is not a drop-in replacement for LB3 in many cases. On the other hand, if we were waiting until LB4 reached functional parity with LB3, then it would take few more years to reach the GA release, considering the size of our team and the scope of LB3 features. To avoid that situation, we decided to cut down the scope, release 4.0 GA early and start gathering feedback about which features are most important to our users. That allows us to better prioritize our efforts on areas where we can add most value. I'll try to find some time later to respond to other parts of your comment in more details, maybe in a blog post or a doc page. |
Thank you @bajtos for this clarification comment about LB4. Maybe the release name "current" is confusing ? Usually, a stable version of software doesn't remove a powerful feature included into the previous release. I think you shouldn't communicate about a stable version, because users thinks "ok, I can now use it on production like the previous version, with some days of migration". I think this could create many frustration for the end developers. I think it's just a communication issue around "current" and "beta". However, thanks for your work on Loopback, it's a great tool, and I hope (and believe) LB4 will be as simply as LB3 after legacy features finished and some useful extensions that reproduce the default behavior of LB3 (I would like to contribute and develop theses extensions, but I need time to completely understand how write good extensions on LB4) |
API explorer is confusing because it show an include filter, even if the feature is missing. @dhmlau I can't use API explorer because it doesn't work with nested object: |
@GuillaumeJasmin, thanks for letting me know. Yes, the UI has limitation to allow nested properties. We've captured this in issue #1470 as well. |
Looks like escaping the parameter name
does not apply |
I agree with you, we need to find a way how to better communicate the status of LoopBack 4 and set reasonable expectations.
Yes please! It's our design goal to keep LoopBack 4+ extensible and allow the community to experiment with different styles of project layout. We don't have bandwidth to implement and maintain all such extensions ourselves, but we are happy to help anybody willing to step up and write such extension themselves. As for repositories, it's already possible to use In #740, @raymondfeng has proposed an extension providing REST API via a base controller class With these two buildings blocks, I imagine one can write a small piece of code accepting a model class an exposing it via REST API, see the mock-up implementation below. It's just an illustration to show what I mean, it will probably not work out of the box and may require cleanup. // usage - this can be automated via a custom Booter
import {Product, Category} from './models';
export class MyApplication extends RepositoryMixin(RestApplication) {
constructor() {
super();
exposeModelViaRest(app, Product);
exposeModelViaRest(app, Category;
}
}
// implementation
function exposeModelViaRest<T extends Entity>(
app: ApplicationWithRepositories,
dataSourceName: string,
modelCtor: Class<T>
) {
const REPOSITORY_KEY = `repositories.${modelCtor.modelName}Repository`;
app.bind(REPOSITORY_KEY).toDynamicValue(() => {
const ds = await ctx.get(`datasources.${dataSourceName}`);
return new DefaultCrudRepository(modelCtor, ds);
});
app.controller(createCrudControllerForModel(modelCtor, REPOSITORY_KEY));
}
function createCrudControllerForModel<T extends Entity>(
modelCtor: class<T>,
repositoryKey: string
) {
// It is not possible to access closure variables like "BaseController"
// from a dynamically defined function. The solution is to
// create a dynamically defined factory function that accepts
// closure variables as arguments.
const name = modelCtor.modelName + 'Controller';
const factory = new Function('BaseController', 'repositoryName', `
class ${name} extends BaseController {
constructor(repository) {
super(repository);
}
}`);
const controllerCtor = factory(CrudController, repositoryName);
// apply @inject() decorator on the first constructor parameter
inject(repositoryKey)(controllerCtor, undefined, 0);
return controllerCtor;
} I am pretty sure there are other ways how auto-wire REST API for models, let's experiment! |
It turns out we already have stories to address this use case, see Declarative Support #565 and Define model relations in JSON file or in JavaScript code #695 |
I have posted a comment in the other issue with a proposal how to implement inclusion of related models at Repository level, see #1352 (comment) |
Closing this issue as a duplicate of
See also:
|
Description
Hi,
I start a big migration since Loopback 4 is now the current release.
However, there is many things not documented.
I try to use include filter, but it seems doesn't work. I'm not able to use it on my current project. I followed examples on the docs.
I first thought that my configuration was bad, so I tried it on
loopback4-example-todo-list
, but it doesn't work on the example too.Current Behavior
When I try this request:
http://localhost:3000/todo-lists?filter={"include": [{"relation": "todos"}]}
or this
I get this 500 error:
Expected Behavior
Should works like Loopback 3
How I can work with relation and the include filter on Loopback 4 ?
Thanks :)
Acceptance Criteria
It should be:
not:
The text was updated successfully, but these errors were encountered: