ember-data

How to save changes on associated models in Ember Data

假装没事ソ 提交于 2019-12-10 10:44:09
问题 I'm running Ember Data 1.0.0 with Ember 1.3.0. I have this data: { "product": { "id": 185588, "name": "USB MIDI Adapter", "images":["imageid1", "imageid2"....] }, "images": [ { "id": "imageid1", "url": "google.com" }, { "id": "imageid2", "url": "google.com2" } ] } And these models: App.Image = DS.Model.extend({ url: DS.attr('string') }); App.Product = DS.Model.extend({ name: DS.attr('string'), images: DS.hasMany('Image') }); In my template I have an edit form to change the url on the

Ember Data - Adapter has no method 'map'

ε祈祈猫儿з 提交于 2019-12-10 10:28:04
问题 Ember Data is picky about JSON responses. I have some 'irregular keys' in the response from my server, and according to the guide I can map those onto the adapter. http://emberjs.com/guides/models/the-rest-adapter/#toc_underscored-attribute-names However, Ember says: Type Error: Object has no method 'map' How do I map keys to a model? I am using Ember v1.0.0 and Ember Data v1.0.0-beta.1 App.ApplicationAdapter = DS.RESTAdapter.extend({ namespace: 'api', host: 'http://localhost:8080' }); App

How to use a string as a primary key with Ember Data?

做~自己de王妃 提交于 2019-12-10 10:08:15
问题 I have the following code: Pult.Zone = DS.Model.extend({ name: DS.attr('string'), authoritative: DS.attr('boolean'), user_id: DS.attr('number'), rulesets: DS.hasMany('Pult.Ruleset') }); Pult.RESTAdapter.map('Pult.Zone', { primaryKey: 'name', rulesets: { key: 'rulesetIds' } }); However, it doesn't seem like is picking up on the primary key correctly. I have rendered a list of all zones. Here's a test case: zones = Pult.store.findAll(Pult.Zone); zones.get('length'); // Returns 10 zones = Pult

Model.find().then() fires before records are actually loaded

末鹿安然 提交于 2019-12-10 04:33:56
问题 I would like to load an entire collection and then just peel off records to use as models one at a time, without doing a roundtrip to the server every time. I've figured out how to use Ember.Deferred to return a promise, but I can't get the promise to resolve at the right time. The following code just outputs "Found 0" ever time: App.PersonRoute = Ember.Route.extend({ model: function(params) { var name = "Erik"; var promise = Ember.Deferred.create(); App.people = App.Person.find(); App.people

How do I get cookies to to be sent with my requests to the backend in ember app?

白昼怎懂夜的黑 提交于 2019-12-10 04:29:14
问题 Is there a way in Ember to send cookies with the requests to the backend? For example: if my client URL is protocol://example.com . The cookies that belong to the same domain will be in the request header when I navigate to protocol://example.com/profile . However, they do not persist in the subsequent request/s the profile route model method makes -> example to protocol://example-host/posts . How do I make those cookies persist? /app/routes/profile.js : import Ember from "ember"; import

Emberjs Data How to load hasMany-Data later

做~自己de王妃 提交于 2019-12-10 03:41:35
问题 I have the following Emberjs Data model: App.File = DS.Model.extend({ like: DS.attr('boolean'), comments: DS.hasMany('App.Comment') }); App.Comment = DS.Model.extend({ file: DS.belongsTo('App.File'), comment: DS.attr('string') }); And preload it with: App.store.load(App.File, {id: 1, like: false}); Now I thought, if I get the comments like this: var f = App.store.find(App.File, 1); var c = f.get("comments"); var c is a empty EmberArray and a request is send to the server. But I don't get a

Where to place fixtures?

拟墨画扇 提交于 2019-12-10 02:56:23
问题 Where should I define fixtures in an Ember JS app generated with ember-cli? I've tried numerous places, such as app.js and within a folder called "fixtures". 回答1: After digging around I discovered that changing Ember.MODEL_FACTORY_INJECTIONS = true; in the file app.js to Ember.MODEL_FACTORY_INJECTIONS = false; is solving the problem. Through this question I also found another solution where you don't have to change the configuration: Instead of defining the fixtures as described you have to

In Ember js, how to create or mock hasMany relationship in unit test

梦想与她 提交于 2019-12-09 21:41:49
问题 I'm unit-testing a model which has properties with DS.hasMany() relationships. Whenever I do the following unit-test, I keep getting this error in my test-runner: Error: Assertion Failed: All elements of a hasMany relationship must be instances of DS.Model, you passed [<Ember.Object:ember367>,<Ember.Object:ember368>] Can someone shed some light into this, please? Model: export default DS.Model.extend({ accounts: DS.hasMany('account'), servicesAccounts: DS.hasMany('services-account'), address:

Add extra url params per model with Ember.js

ぃ、小莉子 提交于 2019-12-09 19:00:43
问题 I have two models: App.Providers = DS.Model.extend({ name: DS.attr('string'), description: DS.attr('string'), logo: DS.attr('string'), products: DS.hasMany('App.Products') }); App.Products = DS.Model.extend({ name: DS.attr('string'), description: DS.attr('string') provider: DS.belongsTo('App.Providers'), }); They are both using the same Adapter. However, for the Products model I want to append an extra url param (the api key) to the url. How can I extend the adapter (or the serializer?) to

How to load belongsTo/hasMany relationships in route with EmberJS

天涯浪子 提交于 2019-12-09 16:28:22
问题 In my EmberJS application I am displaying a list of Appointments. In an action in the AppointmentController I need to get the appointments owner, but the owner always returns "undefined". My files: models/appointment.js import DS from 'ember-data'; export default DS.Model.extend({ appointmentStatus: DS.attr('number'), owner: DS.hasMany('person'), date: DS.attr('Date') }); models/person.js import DS from 'ember-data'; export default DS.Model.extend({ name: DS.attr('string') }); templates