epf icon indicating copy to clipboard operation
epf copied to clipboard

Sideloading?

Open opsb opened this issue 10 years ago • 6 comments

I'm switching to epf from ember-data and I've got a demo working with ember-cli. Problem is I've only figured out how to get it working with embedded associations. Currently my backend generates payloads with the associations sideloaded. The old epf_example demonstrates it but it's an old version and many things have changed (including the disappearance of the sideload option). Is it possible with the current version?

opsb avatar Sep 14 '14 17:09 opsb

Sideloading should work with minimal effort. The implementation is very similar to ED's. Can you give me an example of your payload/model?

ghempton avatar Sep 14 '14 21:09 ghempton

{
    "todos": [{
        "id": 88,
        "title": "one",
        "description": "two",
        "client_id": null,
        "client_rev": null,
        "user_id": 1
    }],
    "users": [{
        "id": 1,
        "name": "blah",
        "todo_ids": [88]
    }]
}

I'm not entirely convinced that I've set things up write with regards to the serializers etc. you can see how I've set things up in https://github.com/opsb/ember-cli-epf-todos/blob/sideloading/client/app/initializers/epf-setup.js (that's the project I'm putting together at the moment).

opsb avatar Sep 14 '14 22:09 opsb

Somethings definitely up because if I don't register

container.register('serializer:model)', Serializer);

then I get the following error (notice the extra bracket at the end of serializer:model)

Error while processing route: todos.index Cannot read property 'embeddedType' of undefined TypeError: Cannot read property 'embeddedType' of undefined
    at __exports__.default.Ember.Mixin.create.embeddedType (http://localhost:4200/assets/vendor.js:78412:26)
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:78452:35)
    at http://localhost:4200/assets/vendor.js:78195:20
    at http://localhost:4200/assets/vendor.js:28064:20
    at Object.OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27906:14)
    at Object.Map.forEach (http://localhost:4200/assets/vendor.js:28062:14)
    at Function.Model.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:78194:42)
    at __exports__.default.Ember.Mixin.create.eachEmbeddedRelationship (http://localhost:4200/assets/vendor.js:78451:14)
    at __exports__.default.Ember.Mixin.create.eachEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:78447:14)
    at __exports__.default.Ember.Mixin.create.eachEmbeddedBelongsToRecord (http://localhost:4200/assets/vendor.js:78421:14) 

opsb avatar Sep 14 '14 22:09 opsb

BTW, would I be better off using https://github.com/coalescejs/coalesce-ember ? I notice you've ES6ified it.

opsb avatar Sep 14 '14 22:09 opsb

Can you try and explicitly add a typeKey property to your model classes. E.g.:

User.reopenClass({typeKey: 'user'});

Also, coalesce-ember is going to be the way forward, but I haven't "officially" released it yet and you are fine using epf for the time time being. Eventually it will be mostly a drop-in replacement.

ghempton avatar Sep 15 '14 00:09 ghempton

@ghempton I've already included the typeKey in all the models. There seems to be something strange going on with the key resolution though, I noticed the value of "type" is "(subclass of ep.model)" (from memory) and when get(type, 'typeKey') is called the result is 'model)' (note the bracket at the end).

opsb avatar Sep 15 '14 03:09 opsb