Skip to content
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

"Relation \"[relation]\" is not defined for MyModel model" #132

Closed
alejandrohenriquez opened this issue Oct 3, 2016 · 5 comments
Closed
Assignees
Milestone

Comments

@alejandrohenriquez
Copy link

Hi:

When I do a query with 3 or more 'joins' I have this error "Relation "[relation]" is not defined for MyModel model":

Example:

var filter: LoopBackFilter = {
            "include": {
                "relation": "company",
                "scope": {
                    "include": {
                        "relation": "installations",
                        "scope": {
                            "include": {
                                "relation": "installation"
                            }
                        }
                    }
                }
            }
        };

this.companyUserApi
    .find(filter)
    .subscribe((x) => {
        console.log('result', x);
    },
    (e) => {
        console.error('error', e.message);
    });

I am not sure if the problem is triggered on the server (Loopback) or in the request (BaseLoopBackApi), but runs well in the loopback explorer view.

The generated url is this:

http://127.0.0.1:3000/api/CompanyUsers?filter[include][relation]=company&filter[include][scope][include][relation]=installations&filter[include][scope][include][scope][include][relation]=installation

Could you help me please ???

Best Regards.

@jonathan-casarrubias
Copy link
Collaborator

Hi @k3n3l thanks for reaching me out, hey so... the result query string seems to be correctly formed, not sure what the issue is... I will need to verify in order to know where the issue is.

@jonathan-casarrubias
Copy link
Collaborator

@k3n3l I have been verifying today and it looks like that after 3 layers the result is broken, so it looks like the first 2 includes would work but any nested include after that won't work.

I have verified the query string and it is correct, I thinks this may be some issue while LoopBack is parsing really nested queries.

In the explorer works because they encode the json as it is, instead of transforming to query string as I do..

I will try to just encode the json and see if works,

@alejandrohenriquez
Copy link
Author

Awesome @jonathan-casarrubias :)
Thank you very much.

@jonathan-casarrubias
Copy link
Collaborator

jonathan-casarrubias commented Oct 3, 2016

@k3n3l It actually worked but only for those GET methods that uses filter, but not to other GET methods that uses no-filtering params, like custom remoteMethods etc..

So, in order to fix all of the cases I need to handle the request depending if the requests contains a LoopBack Filter or not.

I think I will be pushing the fix today, I just need to finish the unit tests for this.

Cheers!
Jon

@jonathan-casarrubias
Copy link
Collaborator

Fixed

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

No branches or pull requests

2 participants