ember-data

How do I get the unique id of ember object when object is initialized?

匆匆过客 提交于 2019-12-12 03:40:44
问题 I have instantiated the model using createRecord. Now how do I get the id of that record before it is saved ? 回答1: You can consider the generateIdForRecord http://emberjs.com/api/data/classes/DS.Adapter.html#method_generateIdForRecord If the globally unique IDs for your records should be generated on the client, implement the generateIdForRecord() method. This method will be invoked each time you create a new record, and the value returned from it will be assigned to the record's primaryKey.

How to get a list of all ember-data Model classes?

佐手、 提交于 2019-12-12 03:21:26
问题 Individual models can be fetched with store.findRecord(modelTypeName, id); ; how can I get a list of all the possible modelTypeName s available in my app? I'm specifically trying to do this from within an app initializer. I'm using ember-cli version 1.13.8 with Ember 2.1.0 Edit : This question is somewhat of a duplicate, but it's not clear in what context he's working. It seems like introspection should be easier to achieve without hacks in an (instance) initializer where you're supposed to

Manually remove record from ember data store

女生的网名这么多〃 提交于 2019-12-12 03:07:36
问题 I am using ember and ember data in my application . How can we remove manually a record from the store in Ember . Currently i am pushing the record to store using push method . I have some issues with ember data save , so i used ajax function for save . Is there any method like record.remove()? 回答1: record.unloadRecord() or store.unloadRecord(record) , additionally you can remove all records for a type, store.unloadAll(type) 来源: https://stackoverflow.com/questions/28648200/delete-records-from

How to get parentRecord id with ember data

99封情书 提交于 2019-12-12 02:54:15
问题 According to the test implemented in ember-data, when we request child records from hasMany relationship, the store makes a get GET to child resources url and send the ids of needed child resources. test("finding many people by a list of IDs", function() { store.load(Group, { id: 1, people: [ 1, 2, 3 ] }); var group = store.find(Group, 1); equal(ajaxUrl, undefined, "no Ajax calls have been made yet"); var people = get(group, 'people'); equal(get(people, 'length'), 3, "there are three people

How do you retrieve where a property/queryParams changes with ember?

核能气质少年 提交于 2019-12-12 02:38:27
问题 Following this post : Ember-data resets queryParam to default value, I got another question. Can I retrieve the place where a property/queryParam changes with some kind of wizardry? I set up an observer, it effectively changes but I want to know where it is triggered. Any suggestions? 回答1: Write the observer like this to print out the stack on the console: observeFoo: function() { var error = new Error(); console.log(error.stack); }.observes('foo') Or, just put a breakpoint inside the

DELETE request is completing before GET request when trying to findRecord and destroyRecord in ember

烂漫一生 提交于 2019-12-12 02:37:49
问题 I have the following code in ember 2.6; ember-data 2.6.1 import Ember from 'ember'; export default Ember.Route.extend({ activate() { var route = this; var sessionId = localStorage.getItem('sessionId'); if (sessionId) { localStorage.removeItem('sessionId'); this.store.findRecord('session', sessionId).then(function found(session) { session.destroyRecord(); route.transitionTo('index'); }); } else { this.transitionTo('sessions.new'); } } }); I have a logout button that has hbs template code as:

Determine if hasMany -> belongsTo item has been created in Ember.js

試著忘記壹切 提交于 2019-12-12 02:34:31
问题 I'm using Ember: 1.3.0-beta.2 and Ember Data: 1.0.0-beta.2 Here's my setup: Models Rise.User = DS.Model.extend({ //.... user_training_plans: DS.hasMany('training_plan', { async: true }), user_training_histories: DS.hasMany('training_history', { async: true }), }); Rise.TrainingHistory = DS.Model.extend({ //.... user: DS.belongsTo('user', { async: true }), training_resource: DS.belongsTo('training_resource', { async: true }) }); Rise.TrainingPlan = DS.Model.extend({ //.... user: DS.belongsTo(

emberdata access the server for additional data

扶醉桌前 提交于 2019-12-12 02:07:00
问题 I have two models - sessions and tests (ember-data) a Session has_many tests. The thing is that in the JSON returned from the server (cannot be changed) has no test_ids in session object so I can't have it in the model. I want to have the ability when I go to #/session/4 - to have ember have another server API call to <server_address>/rest/sessions/4/tests and have it in a "tests" property The current code: App.Session = DS.Model.extend({ logicalId: DS.attr('string'), ..... // tests: DS

Ember Rails model relationship

♀尐吖头ヾ 提交于 2019-12-12 01:57:58
问题 I have inherited an Ember.js application built on top of a Rails API. This was originally running the following: Ember.VERSION : 1.0.0 ember.js DEBUG: Handlebars.VERSION : 1.0.0 ember.js DEBUG: jQuery.VERSION : 1.10.2 but these have been updated to the following: Ember : 1.7.1+pre.f095a455 ember.js DEBUG: Ember Data : 1.0.0-beta.10+canary.30d6bf849b ember.js DEBUG: Handlebars : 1.3.0 ember.js using the ember-rails gem. I am falling into a big blocker issue when trying to save a section model.

json subdocuments in ember data model

风格不统一 提交于 2019-12-12 00:58:27
问题 I have a web service that returns something like this, where there is a fixed envelope and then a body that is json with a schema that depends on "body_schema". I'd like to be able to use ember-data to manage these, with first class fields for the fixed envelope and just an object for the body field. Is this possible? I can't seem to see anything like this in the docs but I can't imagine I'm the first with this issue. {"messages": [ {"id":"5", "from": "someone", "to": "somebody", "body_schema