robsontenorio / vue-api-query

💎 Elegant and simple way to build requests for REST API

Home Page:https://robsontenorio.github.io/vue-api-query

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relations are not applied if one of the relation is null

QuentinGab opened this issue · 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! :)