1
votes

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

3

3 Answers

1
votes

The unknown in <(unknown):ember264> refers to the name of the class. That doesn't mean that your relationship is not loaded correctly. It's just Ember Data using anonymous classes.

To see the data of the relationship you could click on that string and afterwards on content. Another option is passing the full record to the console using the $E link in top right corner. Afterwards you could interact with the record on console, e.g. do a $E.get('testCaseRun.id').

By the way: You don't need to explicitly declare the model name on relationship definition if it's matches the dasherized property name. So testCaseRun: DS.belongsTo('test-case-run') is the same as testCaseRun: DS.belongsTo().

0
votes

Try to declare hasMany relationship with the model name without 's'

testCaseRunLogs: DS.hasMany('test-case-run-log')
0
votes

Finally, I've found the answer of my question.

The problem was that I was using the "underscore" form of the relationships:

"included": [
    {
      "id": "426",
      "type": "test_case_run_log", <= HERE
      "attributes": {
        "payload": "SCREENSHOT"
      },
      "relationships": {
        "test_case_run": {
          "data": {
            "id": "83",
            "type": "test_case_run" <= HERE
          }
        }
      }
    }
  ]

And, changing pathForType was not sufficient. So, I made my backend use dashes. And, it worked.