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

Deleting document #9

Closed
seifsallam opened this issue Feb 20, 2014 · 22 comments
Closed

Deleting document #9

seifsallam opened this issue Feb 20, 2014 · 22 comments
Assignees
Labels

Comments

@seifsallam
Copy link

I have a document with embedded as belongs_to, when i delete the parent document i receive.

TypeError: Cannot read property 'place' of undefined
    at updatePayloadWithEmbeddedBelongsTo (http://localhost:8000/vendor/ember-data-extensions/packages/mixins/lib/embedded_mixin.js:412:15)
    at null.<anonymous> (http://localhost:8000/vendor/ember-data-extensions/packages/mixins/lib/embedded_mixin.js:362:44)
    at http://localhost:8000/vendor/ember-data/ember-data.js:8517:20
    at http://localhost:8000/vendor/ember/ember.js:3368:16
    at Object.OrderedSet.forEach (http://localhost:8000/vendor/ember/ember.js:3211:10)
    at Object.Map.forEach (http://localhost:8000/vendor/ember/ember.js:3366:10)
    at Function.Model.reopenClass.eachRelationship (http://localhost:8000/vendor/ember-data/ember-data.js:8516:42)
    at updatePayloadWithEmbedded (http://localhost:8000/vendor/ember-data-extensions/packages/mixins/lib/embedded_mixin.js:354:8)
    at DS.EmbeddedMixin.Ember.Mixin.create.extractSingle (http://localhost:8000/vendor/ember-data-extensions/packages/mixins/lib/embedded_mixin.js:261:31)
    at superWrapper [as extractSingle] (http://localhost:8000/vendor/ember/ember.js:1239:16) ember.js:3461
Uncaught Error: Assertion Failed: TypeError: Cannot read property 'place' of undefined 
@pixelhandler
Copy link
Owner

@seifsallam can you post a gist or stypi.com page of the models' code; also what versions of Ember, Ember Data are you using? Are you using a version of ember-data-extensions that matches your ember data version? Also include your ApplicationAdapter and ApplicationSerializer code in the shared code snippet. Also, it would be helpful to see the JSON payload for your GET then DELETE responses, I don't then the server sends any payload on DELETE though.

@pixelhandler pixelhandler self-assigned this Feb 20, 2014
@seifsallam
Copy link
Author

I'm using beta.7 for both ember-data and and ember-data-extensions.

PostSerializer = ApplicationSerializer.extend(
  DS.EmbeddedMixin

  attrs:
    place:
      embedded: 'always'
)

App.Post = DS.Model.extend(
  place:    DS.belongsTo 'place'
)

Place = DS.Model.extend(
  country:     DS.attr()
  state:       DS.attr()
  city:        DS.attr()
)

@pixelhandler
Copy link
Owner

Place should also belongTo Post, see: http://emberjs.com/guides/models/defining-models/#toc_defining-relationships

@seifsallam
Copy link
Author

But i don't pass the post id in the place

@pixelhandler
Copy link
Owner

@seifsallam See the example payloads in the docs here: http://pixelhandler.github.io/ember-data-extensions/docs/classes/DS.EmbeddedMixin.html The embedded records have foreign keys.

The mixin doesn't support ID-less records, as Ember Data doesn't support that either. A raw object could be used instead, but then you wouldn't need a place model or the relationship defined in post; and then no need for the mixin either.

@seifsallam
Copy link
Author

Ok. will give it a shot and get back to you

@seifsallam
Copy link
Author

Still the same problem :(

Place = DS.Model.extend(
  country:     DS.attr()
  state:       DS.attr()
  city:        DS.attr()

  post: DS.belongsTo 'post'
)

@pixelhandler
Copy link
Owner

@seifsallam this test file has a bunch of examples how the mixin works: https://github.com/pixelhandler/ember-data-extensions/blob/master/packages/mixins/tests/embedded_mixin_test.js

Perhaps make a jsbin, something like http://emberjs.jsbin.com/iCIXuzI/6/edit?html,js,output that mocks the server responses.

@pixelhandler
Copy link
Owner

@seifsallam perhaps put a breakpoint at line 261 here : https://github.com/pixelhandler/ember-data-extensions/blob/master/packages/mixins/lib/embedded_mixin.js#L257-L264 and inspect the partial variable.

@seifsallam
Copy link
Author

Ok, will investigate further and get back to you

@seifsallam
Copy link
Author

The partial is set as undefined.

@pixelhandler
Copy link
Owner

That's is were it's breaking, so from there you can debug why; or create a jsbin for others to help debug. My guess is that the payload is missing something, the start of the back trace is in extractSingle

@seifsallam
Copy link
Author

Is the data supposed to be like that? with recordId value and empty payload?

partial: undefined
payload: Object
  __proto__: Object
primaryType: (subclass of DS.Model)
recordId: undefined
requestType: undefined
root: "post"

@pixelhandler
Copy link
Owner

Can you make a jsbin example of your issue? (Then I could inspect it)

@seifsallam
Copy link
Author

Ok, will try to do that

@seifsallam
Copy link
Author

@pixelhandler Sorry for the long delay. I've tried to make it work in a jsbin but there are two problems. First i can't get it to work with ember-data-ext. Second i don't know how to make save.() promises succeed

http://emberjs.jsbin.com/bacuh/1/edit

@seifsallam
Copy link
Author

@pixelhandler Any recommended ways for creating and deleting records. As of now i gave up using embedded for belongsTo, only hasMany but still deleting the parent will result in error because the response will not contain the embedded data.

Lets say i have post with many comments. In general any request to the server will expect embedded data, how do you solve this issue for delete knowing that there are no data is sent from the server?

Also for inserting embedded, I get duplicate values after each parent.save()

@pixelhandler
Copy link
Owner

@seifsallam the EmbeddedMixin in this library does not extend any create / delete behaviors that Ember Data already provides only serialization for embedded. The only way I could help debugging the issue you brought up would be to see the code running for example in a jsbin or jsfiddle example. Or if you wrote a failing unit test for the issue. At work I use these extensions for ember data and do have success saving and deleting. Also I find that I need to write patches for open bugs in Ember Data, as it is still beta. I would suggest trying w/o embedded records and see how it goes. As for duplicates after saving a record with a hasMany relationship there have been bugs reported on that topic in Ember Data.

@seifsallam
Copy link
Author

@pixelhandler I've made a version here http://emberjs.jsbin.com/konos/2/edit, i still don't know how to make jsbin work with ember-data-ext

@seifsallam
Copy link
Author

@pixelhandler Any luck here?

@pixelhandler
Copy link
Owner

@seifsallam
Copy link
Author

@pixelhandler Thanks a lot for your help. In your jsbin you were using status 204 when delete succeeds. This fixed the issue of looking for embedded data. It would be awesome if this is mentioned in the wiki. Again thanks :)

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

No branches or pull requests

2 participants