sircamp
sircamp

Reputation: 107

Create and read a record in Ember.js

I'm working with Emeber.js framework; I've created an object like this:

myApp.user=Ember.Object.extend({
    name:null,
    state:false
});

I've also defined an Ember model this way:

myApp.Wuser = DS.Model.extend({
      nome: DS.attr('string'),
      user: DS.attr('mycustomtype') // i want put here a mycustom type (user)
}); 

The question is: how can I create a record? I've tried to write this:

myApp.Wuser.createRecord({nome:"aaa",user:myApp.user.create()});

but an error occurred; do you know how to create a record and how to read it? Thanks in advance!

Upvotes: 1

Views: 938

Answers (1)

Luke Melia
Luke Melia

Reputation: 8389

You create a record on your store.

record = this.get('store').createRecord(MyApp.User, {name: 'Luke'})

To persist it to your server:

this.get('store').commit();

You can also do this for a transaction:

record = transaction.createRecord(MyApp.User, {name: 'Luke'})

Upvotes: 3

Related Questions