# Best Practices when not using Ember Data

**URL:** https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520
**Category:** Uncategorized
**Created:** [March 19, 2013, 12:40am UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520 "2013-03-19T00:40:52Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![MrMcDowall](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mrmcdowall/32/14414_2.png) [@MrMcDowall](https://discuss.emberjs.com/u/MrMcDowall)
#### Post date: [March 19, 2013, 12:40am UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/1 "2013-03-19T00:40:52Z")

</div>

In the situation when you can’t use Ember Data, what are some best practices and recommendations for building your own jQuery Ajax data layer? It would seem like helpers like LinkTo will only work as described when the exact same object instance is used in the route.

Should one build their own Identity map to ensure that object instances are only created once per object id?

What are some patterns people have used in production to support deep hasMany type relations with query results?

---

<div class="post-metadata">

### Author: ![pwagenet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/pwagenet/32/14172_2.png) [@pwagenet](https://discuss.emberjs.com/u/pwagenet)
#### Post date: [March 19, 2013, 2:17pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/2 "2013-03-19T14:17:19Z")

</div>

I’m curious to know a bit about why you’re switching away from Ember Data. I agree that Ember Data isn’t yet the right solution for everything, I would just like to know a bit about why it’s not right for you.

---

<div class="post-metadata">

### Author: ![mikegrassotti](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mikegrassotti/32/14281_2.png) [@mikegrassotti](https://discuss.emberjs.com/u/mikegrassotti)
#### Post date: [March 19, 2013, 3:29pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/3 "2013-03-19T15:29:05Z")

</div>

Suggest you have a look at source code for discourse itself. For example, here is the ember.js code that is used to represent your post: [https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/post.js](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/post.js)

---

<div class="post-metadata">

### Author: ![manmal](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/manmal/32/3794_2.png) [@manmal](https://discuss.emberjs.com/u/manmal)
#### Post date: [March 19, 2013, 3:30pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/4 "2013-03-19T15:30:08Z")

</div>

> [@pwagenet](#):
>
> I’m curious to know a bit about why you’re switching away from Ember Data.

We don’t use it because we want to use meaningful HTTP errors, and there was no way to handle anything other than 422 (validation failed) with find() when we last looked.

---

<div class="post-metadata">

### Author: ![MrMcDowall](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mrmcdowall/32/14414_2.png) [@MrMcDowall](https://discuss.emberjs.com/u/MrMcDowall)
#### Post date: [March 19, 2013, 5:03pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/5 "2013-03-19T17:03:28Z")

</div>

Thanks, I have been following Discourse very closely, but I’m trying to do more than load single records or all records.

My main point of confusion was how to get a record to load a subset of it’s hasMany relationship based on a search query, and still have things like linkTo mark itself active at the right time, and so on. Find query, or using find with a query as it is now, wouldn’t load the records it had previously loaded without the query on the same controller method and returned JSON packet.

---

<div class="post-metadata">

### Author: ![pwagenet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/pwagenet/32/14172_2.png) [@pwagenet](https://discuss.emberjs.com/u/pwagenet)
#### Post date: [March 19, 2013, 5:28pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/6 "2013-03-19T17:28:17Z")

</div>

For what it’s worth find with query always goes to the server because we have no way of guaranteeing that the client has already fetched all the relevant records. If you want to filter associations on the client is there any reason why you can’t just use one of the built-in array filtering methods?

---

<div class="post-metadata">

### Author: ![pwagenet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/pwagenet/32/14172_2.png) [@pwagenet](https://discuss.emberjs.com/u/pwagenet)
#### Post date: [March 19, 2013, 5:29pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/7 "2013-03-19T17:29:19Z")

</div>

That’s a good point. We hope to improve this in the future but for now if you need that, Ember Data isn’t a good option.

---

<div class="post-metadata">

### Author: ![MrMcDowall](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mrmcdowall/32/14414_2.png) [@MrMcDowall](https://discuss.emberjs.com/u/MrMcDowall)
#### Post date: [March 19, 2013, 5:31pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/8 "2013-03-19T17:31:21Z")

</div>

Hello Peter!

Sorry, yes that’s actually the behaviour I wanted (query goes back to the server each time).

Here’s the thing: the records that I’m dealing with are encrypted on the server, and a search of them is actually done on the server using pre-filtered keywords and associations to the encrypted records. That’s why I need the filter query to be resolved on the server, and a subset of the hasMany returned as if it was the full record set.

Then again, maybe I’m doing it all wrong, but I have no reference points.

---

<div class="post-metadata">

### Author: ![joefiorini](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/joefiorini/32/3902_2.png) [@joefiorini](https://discuss.emberjs.com/u/joefiorini)
#### Post date: [March 20, 2013, 5:09pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/9 "2013-03-20T17:09:08Z")

</div>

At that point why not extend the RESTAdapter’s Ajax method to handle the statuses you need?

---

<div class="post-metadata">

### Author: ![fpauser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fpauser/32/13680_2.png) [@fpauser](https://discuss.emberjs.com/u/fpauser)
#### Post date: [March 20, 2013, 8:00pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/10 "2013-03-20T20:00:52Z")

</div>

Thats exactly the point why I abonded ember-data for now in our project. The problem with find() is not only the missing error-handling part but also the unability to solve a failed find() because the record remains in the “loading” state.

---

<div class="post-metadata">

### Author: ![yohsuzuki](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/yohsuzuki/32/14473_2.png) [@yohsuzuki](https://discuss.emberjs.com/u/yohsuzuki)
#### Post date: [March 21, 2013, 8:18pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/11 "2013-03-21T20:18:54Z")

</div>

I’d also like to see some best practices when not using Ember Data.

Ember Data lets you pass a promise-like object into your controller, which has state properties like isLoading in addition to the data. The controller can proxy data in the model. I want to do something just like this without using Ember Data and without having all of the state management code inside of my controller.

Is there a way to use Ember.Object and have it behave similarly to Ember Data’s Model?

---

<div class="post-metadata">

### Author: ![seilund](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/seilund/32/14351_2.png) [@seilund](https://discuss.emberjs.com/u/seilund)
#### Post date: [March 22, 2013, 5:50am UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/12 "2013-03-22T05:50:19Z")

</div>

> [@yohsuzuki](#):
>
> Is there a way to use Ember.Object and have it behave similarly to Ember Data’s Model?

That depends on what you mean by “similarly”?

---

<div class="post-metadata">

### Author: ![yohsuzuki](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/yohsuzuki/32/14473_2.png) [@yohsuzuki](https://discuss.emberjs.com/u/yohsuzuki)
#### Post date: [March 22, 2013, 8:59am UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/13 "2013-03-22T08:59:13Z")

</div>

Did you read the rest of what I wrote?

---

<div class="post-metadata">

### Author: ![ulisesrmzroche](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ulisesrmzroche/32/11317_2.png) [@ulisesrmzroche](https://discuss.emberjs.com/u/ulisesrmzroche)
#### Post date: [March 22, 2013, 6:23pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/14 "2013-03-22T18:23:50Z")

</div>

You’re going to wind up reimplementing a state-manager (a state-manager by any other layer…) if you’re going to want to keep track of record states. Write that into your Ember.Object.

---

<div class="post-metadata">

### Author: ![pangratz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/pangratz/32/14210_2.png) [@pangratz](https://discuss.emberjs.com/u/pangratz)
#### Post date: [March 23, 2013, 8:43pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/15 "2013-03-23T20:43:19Z")

</div>

There is a nice blog post by @eviltrout about Ember without Ember-Data: [Ember without Ember Data | Evil Trout’s Blog](http://eviltrout.com/2013/03/23/ember-without-data.html).

---

<div class="post-metadata">

### Author: ![yohsuzuki](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/yohsuzuki/32/14473_2.png) [@yohsuzuki](https://discuss.emberjs.com/u/yohsuzuki)
#### Post date: [April 3, 2013, 11:46pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/16 "2013-04-03T23:46:17Z")

</div>

Thanks for the great link. I have a specific question that isn’t covered.

I’ve got a route that displays a list of things. Inside the route’s setupController, I’m setting my controller’s content to a particular instance of Ember.ArrayProxy that I wrote (I’m using ArrayProxy instead of Object because it needs addArrayObserver). This works great! When the content of the ArrayProxy changes, it’s reflected in the view via my actual view controller. This ArrayProxy seems to be a good place to put my data retrieval code, and expose pagination functions like loadNext.

Here’s where I run into problems. This ArrayProxy also has some custom state information (e.g. isLoading). I want to be able to bind in the template to “isLoading”. I don’t want to have to bind to “content.isLoading”.

What is it that Ember Data returns from App.Post.find? When a controller’s content is set to App.Post.find(), the view template can bind to both content and isLoading. How can I accomplish the same thing without using Ember Data?

Thanks for the great discussions on this forum and for your expertise here.

---

<div class="post-metadata">

### Author: ![toranb](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toranb/32/16579_2.png) [@toranb](https://discuss.emberjs.com/u/toranb)
#### Post date: [September 16, 2015, 6:56pm UTC](https://discuss.emberjs.com/t/best-practices-when-not-using-ember-data/520/18 "2015-09-16T18:56:57Z")

</div>

I realize I’m really really late to the party but here is an example app showing how I build ember apps w/out ember-data using a simple identity map. My customers often don’t use json api, want very custom object graphs (often many diff patterns inside a single app), embedded json POST (to create a tree of objects w/ dependencies), m2m, m2m self referencing relationships and anything else you can think of.

[https://github.com/toranb/ember-2-skeleton-app](https://github.com/toranb/ember-2-skeleton-app)

This simple app shows how I create a repository to do the ajax work/ a deserializer to parse the json and create model objects (very light as this is a demo app but you get the idea).

The [identity map](https://github.com/toranb/ember-cli-simple-store) I use is ember 1/2/2.1 friendly with no deprecation warnings and I’ve been using it in production apps for almost 18 months now. At the core it’s a simple way to share data structures. If you want dirty tracking/etc I’ve got an optional model you _could_ plugin if needed (also been really happy with this for complex dirty tracking scenarios the last year+).
