I can't send form data with relationships to backend


#1

app/routes/ticket/new.js

import Ember from 'ember';

export default Ember.Route.extend({

  model() {



    return this.get('store').findAll('ticket');
  },

  actions: {

    saveTicket() {
      const idStatus = this.get('idStatus');
      const ticketName = this.get('ticketName');
      //let status = this.get('store').peekRecord('status', idStatus);
      //let newTicket = this.get('store').createRecord('ticket',{name: ticketName});
    //  status.get('ticket').pushObject(newTicket);
    //  status.save().tnen(function () {
     // this.get('store').findRecord('status', idStatus).then(function(status) {
     //   newTicket.set('status', status);
      //});
      //newTicket.save().then(() => this.transitionTo('ticket.index'));
    //});
      let status = this.get('store').peekRecord('status', idStatus);
      let newTicket = this.get('store').createRecord('ticket', {
        name: ticketName,
        status: status
      });
      newTicket.save();

    },

    willTransition() {
      let model = this.controller.get('model');

      if (model.get('isNew')) {
        model.destroyRecord();
      }
    }
  }
});

app/templates/ticket/new.hbs

        <div class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-2 control-label">Тема</label>
                <div class="col-sm-10">
                  {{input type="text" value=ticketName class="form-control" placeholder="Введите тему" }}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Статус</label>
                <div class="col-sm-10">
                  {{input type="text" value=idStatus class="form-control" placeholder="Введите статус" }}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Приоритет</label>
                <div class="col-sm-10">
                    <button type="button" class="btn btn-primary" {{action 'saveTicket' model}}>Сохранить изменения</button>
                </div>
            </div>

        </div>

and when i click button i look in console my “post” request:

{"data":{"attributes":{"name":null,"description":null,"pubdate":null,"duedate":null},"relationships":{"assigned":{"data":null},"owner":{"data":null},"project":{"data":null},"priority":{"data":null},"queue":{"data":null},"status":{"data":null}},"type":"ticket"}}

my models:

models/ticket.js

import DS from 'ember-data';
import Ember from 'ember';
var inflector = Ember.Inflector.inflector;
inflector.plural(/$/, '');
inflector.singular(/s$/i, '');
inflector.uncountable('status');
export default DS.Model.extend({


  name: DS.attr('string'),
  description: DS.attr('string'),
  pubdate: DS.attr('date'),
  duedate: DS.attr('date'),
  assigned: DS.belongsTo('user',{inverse: 'tickets_assigned', async: true}),
  owner: DS.belongsTo('user',{inverse: 'tickets_owners', async: true}),
  project: DS.belongsTo('project',{ async: true}),
  priority: DS.belongsTo('priority',{ async: true}),
  queue: DS.belongsTo('queue',{ async: true}),
  status: DS.belongsTo('status',{ async: true}),
  comments: DS.hasMany('comment', { async: true})
});

models/status.js

import DS from 'ember-data';
import Ember from 'ember';
var inflector = Ember.Inflector.inflector;
//inflector.plural(/$/, '');
//inflector.singular(/s$/i, 's');
inflector.uncountable('status');
inflector.irregular('status', 'status');

export default DS.Model.extend({

  name: DS.attr('string'),
  tickets: DS.hasMany('ticket')
});

sorry for my english )