2
votes

I'm using ember-data v1.0.0-beta.3, active model serializers and the DS.ActiveModelAdapter. I have a model that looks something like this:

App.Listing = DS.Model.extend
 title: DS.attr()
 pickupAddress: DS.belongsTo("address")

App.Address = DS.Model.extend
  listing: DS.belongsTo("listing")
  address: DS.attr()

I want the pickupAddress field to be optional, and my JSON for /listings/{id} looks like this:

{
  "pickup_addresses":[],
  "listing":{"id":2,"title":"Foobar", "pickup_address_id":null}
}

However, ember-data doesn't like this, it gives me this error:

Assertion failed: No model was found for 'pickupAddress'

Does it support this scenario? Is there some option I can pass to the belongsTo? Or should I create some custom adapter?

Thanks

1

1 Answers

3
votes

The problem is with your payload, the sideloaded data need to match a class name, in your sample you have pickup_addresses, the correct is addresses:

{
    "addresses": [],
    "listing": {
        "id": 2,
        "title": "Foobar",
        "pickup_address_id": null
    }
}