robsontenorio/vue-api-query

Relations are not applied if one of the relation is null

Closed this issue · 2 comments

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;
      }

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

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