ember-data

How to implement complex queries with a REST api?

我与影子孤独终老i 提交于 2020-01-01 08:03:10
问题 I'm building an EmberJS app using ember-data. Some of the functionality in my app requires quite complex queries. As an example, let's say I have three entities - students, teachers and classes. If I wanted to get a list of all the students born before 1993 that are taking classes taught by teacher X, how can I do that with a RESTful api? In plain SQL it's easy enough, but I'm unsure of the best practice for implementing this into my API. Do I need to build a custom endpoint alongside my

Ember-Data callback when findAll finished loading all records

天涯浪子 提交于 2020-01-01 04:50:07
问题 With ember-data I'm loading all records of a model with: App.adapter = DS.Adapter.create({ findAll: function(store, type) { var url = type.url; jQuery.getJSON(url, function(data) { var ids = data.map(function(item, index, self){ return item.id }); store.loadMany(type, ids, data); }); } }); The didLoad method is called when each of the record has finished loading. Is there a method to call when all records have finished loading? EDIT Model: App.Article = DS.Model.extend({ title: DS.attr(

Manipulating a RecordArray

女生的网名这么多〃 提交于 2020-01-01 03:49:06
问题 I have a RecordArray that has come back from a App.ModelName.find(). I'd like to do some things with it, like: paginating through the set of records within adding records from another findQuery into the array I may be confused, but it seems like it's difficult (or at least undocumented) on how to work with the records that come back from find()/findAll()/findQuery() other than looping over the set and displaying them as normal. This is further complicated by the array that gets returned from

How can I clone an Ember Data record, including relationships?

此生再无相见时 提交于 2020-01-01 03:12:28
问题 I've figured out that I can clone an Ember Data record and copy its Attributes, but none of the belongsTo / hasMany relationships are cloned. Can I do this somehow if I don't know what relationships would be possible, going off of the relationships that exist? For reference, here is what I've got that will clone an Ember Data record's attributes: var attributeKeys = oldModel.get('constructor.attributes.keys.list'); var newRecord = this.get('store').createRecord(oldModel.constructor.typeKey);

Ember.js array as model's property

风格不统一 提交于 2020-01-01 01:32:09
问题 Cheers! I have some model, and one attribute of it is an array, but for some reasons (I use mongoDB on the server and it's problem with embedded models and ember-data) I can't do somthing like this: App.Foo = DS.Model.extend({ ... numbers: DS.hasMany('App.Bar') )}; App.Bar = DS.Model.extend({ ... number: DS.attr('number') }); I need something like this: App.Bar = DS.Model.extend({ numbers: DS.attr('array') }); But there is no array type of attributes in ember-data, how to be? 回答1: I found

What is the difference between Adapter and Fixture Adapter and REST Adapter, in ember-data?

别来无恙 提交于 2019-12-31 12:08:30
问题 What is the difference between Adapter and Fixture Adapter and REST Adapter, and when to use each one? 回答1: Use DS.FixtureAdapter (or DS.FixtureAdapter.create() ) when you don't (yet?) care to communicate with a backend, but will store your data as "fixtures" in the client. Once you've declared a model: App.Thing = DS.Model.extend({ name: DS.attr('string'), // ... }); You can define your fixtures: App.Thing.FIXTURES = [ { id: 1, name: '...', // ... }, { id: 2, name: '...', // ... }, ]; And

Ember-data: How do I get an aggregated list of models in a collection on a different collection (@each not working)

吃可爱长大的小学妹 提交于 2019-12-31 05:14:25
问题 I am trying to get an aggregated list of employees . Each organization is a model that hasMany employees . var Organization = DS.Model.extend({ name: attr('string'), employees: hasMany('employee', { async: true }) }); On my controller, I have this property. employees: function(){ var employees =[]; this.get('organizations').forEach(function(organization){ employees.pushObjects(organization.get('employees')); }); return employees; }.property('organizations.@each.employees.isFulfilled') When I

Ember-Data: Accessing a list of sideloaded resources?

狂风中的少年 提交于 2019-12-31 01:51:08
问题 I have some JSON that has this structure in the /documents path (the IDs are UUIDs): { "tags": [ { "id": "a33fc396-2428-11e3-8eeb-0800270f33f4", "name": "test" } <more tags not shown> ], "documents": [ { "id": "c41460fa-2427-11e3-8702-0800270f33f4", "name": "file.txt", "tag_ids": [ "a33fc396-2428-11e3-8eeb-0800270f33f4" ] } <more documents not shown> ] } We see that the Tag resource is sideloaded. I'm using ember-data to load the JSON using these routes: App.Router.reopen location: 'history'

add/delete items from Ember Data backed ArrayController

不打扰是莪最后的温柔 提交于 2019-12-30 17:59:53
问题 I'm using an ArrayController in my application that is fed from a Ember Data REST call via the application's Router: postsController.connectOutlet('comment', App.Comment.find({post_id: post_id})); For the Post UI, I have the ability to add/remove Comments. When I do this, I'd like to be able to update the contentArray of the postsController by deleting or adding the same element to give the user visual feedback, but Ember Data is no fun: Uncaught Error: The result of a server query (on App

Ember Data: Saving relationships

独自空忆成欢 提交于 2019-12-30 00:35:28
问题 I need to save a deep object to the server all at once and haven't been able to find any examples online that use the latest ember data (1.0.0-beta.4). For example, with these models: (jsfiddle) App.Child = DS.Model.extend({ name: DS.attr('string'), age: DS.attr('number'), toys: DS.hasMany('toy', {async:true, embedded:'always'}), }); App.Toy = DS.Model.extend({ name: DS.attr('string'), child: DS.belongsTo('child') }); And this code: actions: { save: function(){ var store = this.get('store'),