failing test of embedded records in a filter #568

Closed
wants to merge 1 commit into
from

4 participants

@jefflab

I get the following error when using a filter with a server query for embedded records:

TypeError: Cannot call method 'hasOwnProperty' of undefined

I don't get the same error with a normal find, so I assume the error is in the filter logic somewhere.

This pull request contains a failing test to demonstrate the problem.

@yrik

Also have that issue.

@sly7-7

Is it still an issue ? I tried to rewrite the test against master, but I don't get this error.... but an other one... Could you try to write it against master ?

@jefflab

Sorry for the delayed response. I'll try to work on rewriting this test against master in the next few days.

@sly7-7

I'm late too... Thanks for this :)

@sly7-7

Ok, I've just wrote a test against master, and the behavior you described now works.

test("the filter method with server query works with embedded records", function() {
  var MyAdapter = DS.Adapter.extend();

  Person.reopen({
    dogs: DS.hasMany(Dog)
  });

  MyAdapter.map(Person, {
    dogs: { embedded: 'always' }
  });

  var adapter = MyAdapter.create();
  store.set('adapter', adapter);

  adapter.findQuery = function(store, type, query, array) {
    this.didFindQuery(store, type, { persons: [
      {id: 1, name: "Yehuda Katz", dogs: []},
      {id: 2, name: "Tom Dale", dogs: [{ name: "Tank" }, {name: "Fluffy"}] }
    ]}, array);
  };

  var filter = store.filter(Person, { name: "Tom Dale" }, function(data) {
    return data.get('name') === "Tom Dale";
  });

  equal(get(filter, 'length'), 1, "The filter has an item in it");

  var tom = filter.objectAt(0);
  equal(tom.get('dogs.length'), 2, "loads embedded records");
  equal(tom.get('dogs').objectAt(0).get('name'), 'Tank', "loads embedded record attributes");
});

@stefanpenner I don't know if we should just close it, or if this test is relevant enough to push it.

@jefflab

@sly7-7 Thank you for finishing this. Your test looks good.

@tomdale
Ember.js member

@sly7-7 I'm gonna close this, but please feel free to submit a PR for a test that would catch for a regression.

@tomdale tomdale closed this May 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment