

Ember Data and MongoDB - dbushell
http://dbushell.com/2013/04/25/ember-data-and-mongodb/

======
avolcano
I think the most important takeaway from this is how malleable and extendable
Ember Data and its RESTAdapter are. It doesn't always (or, to be honest,
almost never) works out of the box, but it's very easy to tweak.

Anyways, as for the way you're handling relationships:

The RESTAdapter works like it does because it expects hasMany<->belongsTo
relationships. In that relationship:

\- It can load the child record from an array of IDs on the parent.

\- When a child record is updated, it is saved back to the server without
including the parent.

\- When a child record is added, it only saves itself back to the server. The
_server_ is expected to handle adding that record to the parent resource.

\- Similarly, when a child record is deleted, it is saved back to the server
and the _server_ should remove it from the parent resource.

Essentially, the client shouldn't need to save the list of children back to
the server.

The downside of this is that this doesn't actually work in a hasMany<->hasMany
relationship, because a record in that relationship _does_ need to send back
the list of resources - it's the same as the way a belongsTo record will
include its parent.

Regardless, there's no obvious harm in overriding RESTAdapter to do this, and
it shouldn't impact the way that a regular hasMany<->belongsTo relationship is
handled. Just make sure that the client-side records always have a current
representation of their relationships, or you might end up saving back
incorrect versions of the records.

~~~
dbushell
Thanks, great explanation. I'm finding Ember Data really nice to use from my
experience so far. I look forward to seeing an official release and
documentation. For the time being the source code is heavily commented if you
want to see what can be extended.

~~~
avolcano
I've been working on getting API documentation added to ember.js.com, fwiw:
<https://github.com/emberjs/website/pull/457>

------
benhowdle89
Ember?

What's Ember? Do you mean Ember.js?

~~~
Jhsto
Ember Data and Ember.js are different projects, although strongly related.
Ember Data can be used to render database objects on client side with ease.

OP: Nice post. I've actually spent the last few days on the very same topic. I
had the same problem with MongoDB's _id and everything I found on Google
seemed to show different approach, from which none worked. Ultimately I
changed to Parse and everything worked out of the box.

~~~
oneplusone
I would be interested to see how you hooked up Ember Data to Parse.

~~~
Jhsto
I used this: <https://github.com/clintjhill/ember-parse-adapter>

Basically just link the JS and add your API keys.

