ebryn/ember-model — pull request #86 by drogus (2013-06-24 23:00:08+00:00)
Title: [WIP] Partially loaded recrods

I've done a first *realy* simple stab at partially loaded records and I would like to start a discussion about it. It will need to expose new APIs, so I would like to have a blessing before going to deep into implementation.

The purpose of partially loaded records is to allow creating a record from partial data and act if the missing data is accessed. For example we may have a blog with a `Post` model, which has 2 attributes: `title` and `body`. A body can be quite big and we don't show it on the list of posts, so to make the posts list to load turbofast, we can just return a representation containing `title` and load `body` only if a visitor goes to detailed post view.

The code could look like this:

```javascript
var Post = Ember.Model.extend({
id: attr(String),
title: attr(String),
body: attr(String),

missingAttributeAccessed: function(key) {
// reload record if we're missing any attributes
this.reload();
}
});

Post.loadPartially({
id: '1',
title: 'Really long blog post'
});

var post = Post.find('1');

post.get('title'); // => 'Really long blog post'

post.get('body'); // => null
// at this point missingAttributeAccessed is called
```

Current implementation ignores associations, mainly because I would like to implement `belongsTo` and `hasMany` without embedded data before I continue work on this.

Any feedback and comments on both implementation and public API is welcomed.