Skip to content

Relations are not applied if one of the relation is null #133

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

Closed
QuentinGab opened this issue Oct 25, 2020 · 2 comments · Fixed by #134
Closed

Relations are not applied if one of the relation is null #133

QuentinGab opened this issue Oct 25, 2020 · 2 comments · Fixed by #134

Comments

@QuentinGab
Copy link

QuentinGab commented Oct 25, 2020

Relations are not applied if one of the relation is null.
Exemple:

relations() {
        return {
            post: Post,
            comments: Comment,
        };
    }

and database response

{
    post: null,
    comments: [
        {title: 'hello world'}
    ]
}

will not apply the relation on comments.
Maybe _applyRelations should just ignore null values rather than ending the loop :

  _applyRelations(model) {
    const relations = model.relations()

    for(const relation of Object.keys(relations)) {
      const _relation = getProp(model, relation)

      if (!_relation) {
        return;
      }
@Peter-Krebs
Copy link
Collaborator

@JoaoPedroAS51 Ignoring null values seems to be a better approach. Can you deliver a fix?

@JoaoPedroAS51
Copy link
Collaborator

Hey! Good catch! Fix is on the way! :)

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

Successfully merging a pull request may close this issue.

3 participants