emberjs/data — pull request #334 by stefanpenner (2012-07-19 05:23:43+00:00)
Title: Failing Test + Fix:

(moved from https://github.com/emberjs/data/pull/325)
reason: rw is on vacation, and we want this merged into the relationship-improvements branch.

## TL;DR ##
Adding records client-side to RecordArrays does not properly update indexes.

## Problem ##

Given a model that has a relationship,
```javascript
var Comment = DS.Model.extend({
posts: DS.belongsTo("Post")
});

var Post = DS.Model.extend({
comments: DS.hasMany("Comment")
});
```
when creating a client-side associated object,

```javascript
var post = store.createRecord(Post);
var comment = store.createRecord(Comment);
post.comments.pushObject(comment);
```

and then deleting it,

```javascript
post.deleteRecord();
```

the RecordArray is not informed of its deletion:

```javascript
post.comments.contains(comment) === true;
```

When associations are created client-side, the appropriate indexes are not updated.

## Solution ##
Update the indexes of the collection on insertion (pushObject), so that the record is removed from the collection when it is deleted.