vendredi 22 novembre 2019

Ember unknown relationship

I'm currently building software with Rails + Ember 3.12, but hitting a strange issue.

My models are the following:

// test-case-run
import DS from 'ember-data';
const { Model } = DS;

export default Model.extend({
  testCase: DS.belongsTo('test-case'),
  testCaseRunLogs: DS.hasMany('test-case-run-logs')
});

// test-case-run-log
import DS from 'ember-data';
const { Model } = DS;

export default Model.extend({
  testCaseRun: DS.belongsTo('test-case-run'),
  payload: DS.attr('')
});

And, my backend is returning the following payload:

{
  "data": {
    "id": "83",
    "type": "test_case_run",
    "relationships": {
      "test_case": {
        "data": {
          "id": "90",
          "type": "test_case"
        }
      },
      "test_case_run_logs": {
        "data": []
      }
    }
  }
}
{
  "data": {
    "id": "83",
    "type": "test_case_run",
    "relationships": {
      "test_case": {
        "data": {
          "id": "90",
          "type": "test_case"
        }
      },
      "test_case_run_logs": {
        "data": [
          {
            "id": "426",
            "type": "test_case_run_log"
          }
        ]
      }
    }
  },
  "included": [
    {
      "id": "426",
      "type": "test_case_run_log",
      "attributes": {
        "payload": "SCREENSHOT"
      },
      "relationships": {
        "test_case_run": {
          "data": {
            "id": "83",
            "type": "test_case_run"
          }
        }
      }
    }
  ]
}

I've got a custom adapter defining:

  pathForType(type) {
    return underscore(pluralize(type));
  }

So, I think that everything should go well.

However, when I get into the ember inspector, I've got the following: enter image description here

It seems that my relationship is not loaded properly. And, I cannot access any data, such as:

log.get('testCaseRun') // that is null 
run.get('testCaseRunLogs.length') // it returns 0 

This is quite strange, as my records are loaded in the store, but not their relationships. I have no idea on how to troubleshoot this, since the amount of information I can get from ember is quite limited (there is no error, the format looks good, ...).

Could someone help me to understand what's wrong with my calls? I've tried many things, such as renaming my models, but this does not improve the situation.

Moreover, this model is the only one, which I have problem with. All my other models don't have this problem. So, that's a bit weird.

Thanks a lot




Aucun commentaire:

Enregistrer un commentaire