toranb / ember-data-django-rest-adapter

An ember-data adapter for django web applications powered by the django-rest-framework
MIT License
152 stars 26 forks source link

Update to ember-data 1.0.0 beta.10 / ember 1.7.0. #101

Closed benkonrath closed 10 years ago

benkonrath commented 10 years ago

Just getting this pull request up so other can see it. There are still 16 test failures to work out.

benkonrath commented 10 years ago

I'm working through this error:

PhantomJS 1.9.7 (Linux) polymorphic integration tests test polymorphic hasMany FAILED
    Died on test #1     at /home/ben/Development/ember-data-django-rest-adapter/node_modules/qunitjs/qunit/qunit.js:132
        at /home/ben/Development/ember-data-django-rest-adapter/node_modules/qunitjs/qunit/qunit.js:108
        at /home/ben/Development/ember-data-django-rest-adapter/tests/adapter_polymorphic_tests.js:50: Assertion Failed: You defined the 'messages' relationship on App.User, but multiple possible inverse relationships of type App.User were found on App.Message. Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses
    Error: Assertion Failed: You defined the 'messages' relationship on App.User, but multiple possible inverse relationships of type App.User were found on App.Message. Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses

http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses

So I need to add the inverses but I don't understand the modelling. Looking at the Author model hierarchy, are the Company.name and Company.messages fields intended to override User.name and User.messages? Couldn't these fields just be in the parent class?

The Author.messages inverse seems straight-forward but I'm not sure how to setup the inverse for Company.messages. Is this correct?

App.User = App.Author.extend({
  ...
  messages: DS.hasMany('message', { polymorphic: true, inverse: 'author' })
  ...
});

App.Company = App.Author.extend({
  ...
  messages: DS.hasMany('message', { polymorphic: true, inverse: 'author' }),
  ...
});

I'm also not sure how to setup the inverse for Message.receiver. Is there an inverse for this in the Author model hierarchy?

benkonrath commented 10 years ago

I've added a couple of commits for setting up the inverse relationships for people to follow along.

dustinfarris commented 10 years ago

@pdufour, any thoughts here?

pdufour commented 10 years ago

Looking at the Author model hierarchy, are the Company.name and Company.messages fields intended to override User.name and User.messages? Couldn't these fields just be in the parent class?

Yup, could definitely be part of the parent class, not sure why I didn't do that the first time. Although I wouldn't say Company.name overrides User.name, Company can be an Author, and User can be an Author, but Company doesn't inherit from User. Although you could if you wanted to.

The Author.messages inverse seems straight-forward but I'm not sure how to setup the inverse for Company.messages. Is this correct?

Looks right to me, but I haven't used the inverse property yet, and I'm still wrapping my head around what it's for.

I'm also not sure how to setup the inverse for Message.receiver. Is there an inverse for this in the Author model hierarchy?

Thinking out loud here, but from what I can gather, to determine the inverse property.. If you have a model called Foo, with a relationship could Bar, you would ask "what field on Bar links back to Foo?"

So in the case of the Message model, I don't think there would be an inverse for the author and receiver fields? Unless you consider Author.messages as the inverse? But that would take two links to get back to Author.

image

dustinfarris commented 10 years ago

This work is moving to dustinfarris/ember-django-adapter