website icon indicating copy to clipboard operation
website copied to clipboard

Tutorial -> Ember Data -> Incorrect usage of Mirage

Open JonForest opened this issue 10 years ago • 10 comments

The documentation in this talks about:

Let's now configure Mirage to send back our rentals that we had defined above by updating mirage/config.js

This is actually located at app/mirage/config.js

In addition (apologies if this should be a separate issue), the content of config.js is shown as:

this.get('/rentals', function() {
    return {
      data: [{
        type: "rentals",
....

When I use this, I get the following output in my Chrome console:

WARNING: Encountered "data" in payload, but no model was found for model name "datum" (resolved model name using super-rentals@serializer:-rest:.modelNameFromPayloadKey("data"))

I changed data to rentals in the rentals array. I.e.

this.get('/rentals', function() {
    return {
      rentals: [{
        type: "rentals",
....

This hasn't solved the issue in that the data is still not being rendered in the sample website, but at least it's stopped the console error and is looping over each item in the array.

JonForest avatar Dec 09 '15 19:12 JonForest

In the sample data used in the config.js, the data required is organised like this:

type: "rentals",
id: 2,
attributes: {
   title: "Urban Living",
   ....
}

The model and data usage is set up to work without the attributes nested object, like

type: "rentals",
id: 2,
title: "Urban Living",
 ....
}

I don't know enough yet to understand what the best practice solution for that is; whether there should be a different model definition, some kind of transform, or if for the sake of the tutorial whether we should just change the data format. I'm changing the data format so I can continue.

JonForest avatar Dec 09 '15 19:12 JonForest

@JonForest Could you open this issue on the Guides repo instead? That is more actively watched than this repo ... https://github.com/emberjs/guides/issues :+1:

acorncom avatar Dec 10 '15 22:12 acorncom

Cool. Will do. Cheers.

JonForest avatar Dec 13 '15 07:12 JonForest

@JonForest change ember-data version to 2.0 in bower.json and install bower again.version incompatibility between ember and ember-data because of this problem in loading data

jprassanakumar avatar Dec 21 '15 10:12 jprassanakumar

@jprassanakumar I was running into the same problem when doing an ember cli tutorial (http://www.thetechcofounder.com/getting-started-with-ember-js-using-ember-cli/). Your suggestion works perfectly for me :+1:

TifPun avatar Dec 23 '15 21:12 TifPun

@jprassanakumar @TifPun there's a whole paragraph about making sure you have the proper dependencies. I'll try making it more noticeable.

locks avatar Dec 23 '15 23:12 locks

@JonForest Thank you for posting those fixes. I slammed into these today.

nicholaswagner avatar Jan 19 '16 13:01 nicholaswagner

Thanks @jprassanakumar, fixed the problem for me

jeremygehrshg avatar Feb 01 '16 23:02 jeremygehrshg

Thanks @jprassanakumar, fixed the problem for me

voodoo avatar Feb 11 '16 18:02 voodoo

It may be the version issue, but it can be fixed by changing data -> rentals, and removing type:'rentals'. return { rentals: [{ id: 'grand-old-mansion', title: 'Grand Old Mansion', .... type: 'Estate', .... } ]

ghost avatar Dec 08 '16 06:12 ghost