jeudi 21 octobre 2021

Ember not population model even after successful API call

My route.js

export default Route.extend(ResetScrollMixin, {

  model(params, { queryParams }) {
    return hash({
      ruleSetVersions: this.store.queryRecord('rule-set-versions', {
        rule_set_id: params.rule_set_id,
        is_archived: false,
        page: queryParams.page || 1
      }),
      ruleSet: this.store.findRecord('rule-set', params.rule_set_id)
    })
  },

  actions: {
    reload() {
      location.reload()
    }
  }
});

Models

rule-set-versions.js

export default DS.Model.extend({
    rule_set_versions: DS.belongsTo('paginated-versions')
})

paginated-versions.js

export default DS.Model.extend({
    rule_set_versions: DS.hasMany('rule-set-version'),
    pagination: DS.belongsTo('pagination'),
})

pagination.js

export default DS.Model.extend({
    page_number: DS.attr('number'),
    page_size: DS.attr('number'),
    total_pages: DS.attr('number'),
    total_rows: DS.attr('number')
})

rule-set-versions.js this is a serializer for rule-set-versions model

var underscore = Ember.String.underscore;
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
      rule_set_versions: {
        serialize: "id",
      },
      pagination: {
        serialize: "id",
      },
    },
    keyForRelationship: function (rawKey) {
      console.log("here")
      return underscore(rawKey) + "_id";
    }
})

My API Response which truncated.

{
    "rule_set_versions": {
        "id": 100,
        "pagination": {
            "id": 100,
            "page_number": 1,
            "page_size": 5,
            "total_pages": 1,
            "total_rows": 3
        },
        "rule_set_versions": [{
            "id": 934,
          ....
        }]
    }
}

I am getting null when I do this.get("model.ruleSetVersions"). I tried and followed the documentation as well but I couldn't come up with the solution.




Aucun commentaire:

Enregistrer un commentaire