Add parent to the findMany adapter signature? #573

toranb opened this Issue Jan 2, 2013 · 3 comments


None yet

2 participants


The REST backend I'm writing an adapter for requires the parent id and I found a way to hack this in for a spike adapter I'm playing around with currently.



The above commit shows the basic changes required to get this parent record and I'll submit a full blown pull request to add this but before I go through the work I wanted to see if there way any other way to get this information (to avoid changing the method signature).

I got half of the parent data needed by using the associationsByName.

belongsTo: function(type) {
        var association = undefined;
        var associations = get(type, 'associationsByName');
        associations.forEach(function(key, meta) {
          key = meta.key || key;
          if (meta.kind === 'belongsTo') { association = key; }
        return association;

But once I got the type back for the belongsTo I still couldn't get the id of the parent using the following (I assume because of a timing issue).

var association = this.belongsTo(type);
var record = type.find(ids[0]);
record.get(association).get('id'); //no id is available yet (timing related?)

Does anyone else know of a way around this or should I submit a pull request to modify the findMany method signature?

@toranb toranb referenced this issue in toranb/ember-code-camp Jan 5, 2013

Can't bookmark a page that is not the root url #1


This issue appears to be more complex if we just add the parent record to the fetchMany signature because of a timing issue someone discovered on a recent project I did using this hack.


If someone does a find (async) along with a fetchMany for related models my hack above is skipped altogether.

Instead it drops down to load the related models using fetch => fetchUnloadedReferences

At this point I've lost the parent directly and after a little hacking it would seem this approach should not be taken at all. Instead could we just add or get a reference to the parent from the object itself?

This would avoid the method signature hack I show above and would greatly simplify the adapter work for those REST apis like mine that require the parent id to lookup related models.

Can anyone verify this is a good idea or explain how I can get at the parent model reference today? (even in the async loading case I linked to above) ?


It appears that in the fetch method (just before the fetchUnloadedReferences method is invoked) "this" has the correct owner property (the correct parent type and id anyway)

fetch: function() {
    var references = get(this, 'content'),
        store = get(this, 'store'),
        type = get(this, 'type')
        parent = get(this, 'owner');

    store.fetchUnloadedReferences(type, references);                                                               

Yet for some reason when I do the following inside the fetchMany ... I don't see this property "owner" any reason why it would be lost?

var record = type.find(ids[0]); //from within the fetchMany in my adapter
var parent = get(record, 'owner'); //undefined
Ember.js member

@toranb i think this is closed, just let me know if i am mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment