getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Sideloading? #144

Open opsb opened 9 years ago

opsb commented 9 years ago

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?

ghempton commented 9 years ago

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

opsb commented 9 years ago
{
    "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 commented 9 years ago

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 commented 9 years ago

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

ghempton commented 9 years ago

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.

opsb commented 9 years ago

@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).