How to represent arrays within ember-data models?

Well… It was a little bit difficult but mixing all answers in this post I made it work. Firstly, you should create a transform for the new type “array”: DS.ArrayTransform = DS.Transform.extend({ deserialize: function(serialized) { return (Ember.typeOf(serialized) == “array”) ? serialized : []; }, serialize: function(deserialized) { var type = Ember.typeOf(deserialized); if (type == ‘array’) … Read more

Ember.js & Ember Data: How to create record with hasMany relationship when the parent and child don’t exist yet

I’m just figuring this out myself, but I just did it this way and it works… For starters, when you this.store.createRecord(‘basket’, {}) it should come with an empty array for its fruits property. So, do this: var basket = this.store.createRecord(‘basket’, {}); basket.get(‘fruits’).addObject(this.store.createRecord(‘fruit’, { name: ‘orange’, color: ‘orange’ })); basket.get(‘fruits’).addObject(this.store.createRecord(‘fruit’, { name: ‘banana’, color: ‘yellow’ })); … Read more

How to cache query result in ember data

I’m not an Ember expert but I think you can address your problem with a pure JS solution. Given Ember Data queries return Promises, e.g. return this.store.findAll(‘blog-post’); // => Promise, we can cache promises in a simple object with higher order functions (functions that return functions). The object cache could be replaced with localStorage, sessionStorage, … Read more

How should errors be handled when using the Ember.js Data RESTAdapter?

This weekend I was trying to figure the same thing out. Going off what Luke said, I took a closer look at the ember-data source for the latest commit (Dec 11). TLDR; to handle ember-data update/create errors, simply define becameError() and becameInvalid(errors) on your DS.Model instance. The cascade triggered by the RESTadapter’s AJAX error callback … Read more

Ember.js: Reloading a .hasMany relationship given through “links” in payload

DS.Model.reopen({ reloadLink: function (linkKey) { if ($.isArray(linkKey)) { var promises = []; for (var i = 0; i < linkKey.length; i++) { promises.push(this.reloadLink(linkKey[i])); } return Em.RSVP.all(promises); } else { var rel = this._relationships[linkKey]; if (rel) { if (rel.reload) { return rel.reload(); } else if (rel.fetchLink) { return rel.fetchLink(); } } } } }); Example: model: … Read more

Ember CLI testing complicated model relationships

If you are using Ember default ‘Ember-QUnit’ then you have to list all the models in needs. But there is an alternative for testing which I am using i.e. ember-data-factory-guy. This is used to create factory instead of fixture data when testing Model, component, controller etc. You can go through it. https://github.com/danielspaniel/ember-data-factory-guy

infinite scroll with ember.js (lazy loading)

I’ve implemented an infinite scroll mechanism at the GitHub Dashboard project, I’m currently developing. The feature is added in commit 68d1728. The basic idea is to have a LoadMoreView which invokes the loadMore method on the controller every time the view is visible on the current viewport. I’m using the jQuery plugin inview for this. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)