Creating and deleting records in model to perform operations in the store


#1

I need help on how i can create and delete records about the transactions of an Invoice here

This is the scenario:

My Models

App.Invoice = DS.Model.extend({
  title   	    : DS.attr('string'),
  transactions  :  DS.hasMany('transaction', { async:true})
});

App.Transaction = DS.Model.extend({
  quantity: DS.attr('string'),
  total: DS.attr('string'),
  invoice: DS.belongsTo('invoice'),
  fares: DS.hasMany('fare', {async:true})
});

App.Fare = DS.Model.extend({ 
  name: DS.attr('string'),
  transaction: DS.belongsTo('transaction')
});


App.Invoice.reopenClass({
  FIXTURES: [
     {
       id: 1,
       title: 'Test',
       transactions: [1, 2]
     }
  ]
});

App.Transaction.reopenClass({
  FIXTURES: [
     {
        id: 1,
        quantity: '100'
     },
     {
        id: 2,
        quantity: '200'
     }
    ]
});

App.Fare.reopenClass({
  FIXTURES:[
    {
        id: '1',
        name: '100'
    },
    {
        id: '2',
        name: '200'
    }
   ]
});

These are my controllers which can perform operations in the store but i need to do with also the fares and the total, how can i change my controllers to make it working?

  actions:{
    add: function() {
      var quantity = this.get('quantity');
      console.log('quantity: ' + quantity);
      var transaction = {quantity: quantity};
      this.store.createRecord('transaction', transaction);
    },
    delete: function() {
      var quantity = this.get('quantity');
      console.log('quantity: ' + quantity);
      var transactionId = 0;
      this.store.deleteRecord('transaction', transactionId);
    }
  }