escalant3 / ember-data-tastypie-adapter

An adapter to connect django applications powered by django-tastypie with ember.js apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

embedded: loaded - do not populate object's content properly

yrik opened this issue · comments

There is a problem when working with latest ember-data.

Query with using of embbed field do not populate Object content properly,

Examples

s = App.Staple.find(1)

s._data.belongsTo.album
Object {created="2012-12-26T05:41:37", description="30a", ...}

  • wrong version

p._data.belongsTo.language
Object {id="1", clientId=7, ...}

  • right version

Can you provide more information about this? Which are yout models?

App.Staple = DS.Model.extend({
    album: DS.belongsTo('App.Album'),
    object: DS.belongsTo('App.Object'),
    staple_origin: DS.belongsTo('App.Staple'),
    });

App.Album = DS.Model.extend({
    staples: DS.hasMany('App.Staple'),
    staple: DS.belongsTo('App.Staple'),
    });

App.Adapter.map('App.Staple', {
    object: {embedded: 'load', key: 'object_id'},
    album: {embedded: 'load', key: 'album_id'}
});


// Ember-data store using the Django Tastypie adapter
App.store = DS.Store.create({
    revision: 11,
    adapter: App.Adapter
});


// Start!
App.initialize();

At django part

class StapleResource(ModelResource):
  album_id = fields.ToOneField(AlbumResource, 'album', null=True, full=True)
  object_id = fields.ToOneField('staples.api.ObjectResource',
                                'object', null=True, full=True)
  staple_origin_id = fields.ToOneField('staples.api.StapleResource',
                                    'staple_origin', null=True)

class AlbumResource(ModelResource):
  staple_id = fields.ToOneField('staples.api.StapleResource', 'staple', null=True)
  staples = fields.ToManyField('staples.api.StapleResource', 'staples', null=True)

I've investigated a bit deeper and see that this problem exist at only one page.
That page differs only by these rows

App.StaplesDetailsRoute = Ember.Route.extend({
    setupController: function(controller, model) {

        site_staples =  App.Staple.find({object_id__site_id: model.get('site')});

    }
    });

It's addiional request that collects data for the same model but with another filtering options.

Is that all you have in your Django Resources? If you want to do any find with a field that it's not the "id", you need to specify meta-data. In Tastypie, in the class Meta you must add those field in which you allow filtering.

Also, I haven't been able to find time and test the adapter against the latest ember-data. In the README you can find the exact hash I do know it passes all the tests. It supports revision:11 that was the latest BreakingChanges in the oficial ember-data.

Support for embedded fields has been added again with the 1.0-b5 update