Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sideloading? #144

Open
opsb opened this issue Sep 14, 2014 · 6 comments
Open

Sideloading? #144

opsb opened this issue Sep 14, 2014 · 6 comments

Comments

@opsb
Copy link

opsb commented Sep 14, 2014

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
Copy link
Contributor

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
Copy link
Author

opsb commented Sep 14, 2014

{
    "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
Copy link
Author

opsb commented Sep 14, 2014

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
Copy link
Author

opsb commented Sep 14, 2014

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

@ghempton
Copy link
Contributor

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
Copy link
Author

opsb commented Sep 15, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants