12

Ember data createRecord creates multiple records

 2 years ago
source link: https://www.codesd.com/item/ember-data-createrecord-creates-multiple-records.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ember data createRecord creates multiple records

advertisements

When I inspect Data in ember inspector I see multiple record one with id(int) and one without id(null).

Using ember 2.9.1

save: function(){
  var title = this.get('title');
  this.store.createRecord('post',{ title:title }).save();
  this.setProperties({ title:''});
  this.transitionToRoute('posts');
}

Node Backend

router.post('/', function(req, res, next) {
  post.create({
    title: req.body.data.attributes.title
  }).then(function () {
    res.set('Content-Type','application/vnd.api+json');
    return res.send({
      "msg": "post created successfully",
      data:null
    });
  });
});


return res.status(201).send({
  data:{
    type:'post',
    attributes:{
      id:post.id,
      name:post.title
    }
  }
});

The following code works properly.This is a known issue in ember data.

Related Articles

FactoryGirl creating multiple records

I'm trying to get in the habit of writing specs, however, this is becoming increasingly frustrating. Assume I have two simple models: User and Story. Each model uses a belongs_to relation. Each model uses a validates :foo_id, presence: true as well.

The Ember data model created with createRecord without params does not appear

We have an example ember app where we CRUD recipes. For the route where we create a new Recipe, if we pass attributes into createRecord like so: Cookbook.RecipesNewRoute = Ember.Route.extend model: -> Cookbook.Recipe.createRecord(title: "blank&quo

the embers data inject metadata when recording

I'm developing a Ember.js app and at the moment I try to implement user registration. Until now I found two ways to get this working, but both have some disadvantages. One way is to have a registration controller, which does a custom ajax post with e

How to update Ember data after creating with JSONAPI?

I'm not sure what I'm missing here but after sending a save() request to the API, I'm finding that the list within the template is not updating. I'm using the JSONAPI adapter, and after the create has been completed, it returns a corresponding post-c

Extracting corresponding data values ​​from multiple records using a function

I have a dataframe (df1) containing many records Each record has up to three trials, each trial can be repeat up to five times. Below is an example of some data I have: Record Trial Start End Speed Number 1 2 1 4 12 9 1 2 4 6 11 10 1 3 1 3 10 17 2 1

Create multiple records using a single form (Non-nested Attributes)

In my application I have a Thought model which has content and author attributes. I want to create multiple thoughts at once using new form. But this is not a case of nested forms as i am not using any associated models. Please suggest some solution.

Rails: Create multiple records in a single shipment using a multiple selection field

I have the following form that WORKS: <%= form_for @task do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p> <%= f.label :color_id %><br /> <%=

r manipulation of data creating multiple records

I have two data frames as the following. v1 v2 a 0.3 b 0.5 c 0.6 d 0.5 and v3 aa ab ac ad I want the data frames to be as follows. v1 v2 v3 a 0.3 aa a 0.3 ab a 0.3 ac a 0.3 ad b 0.5 aa b 0.5 ab b 0.5 ac b 0.5 ad c 0.6 aa c 0.6 ab c 0.6 ac c 0.6 ad d

How do I create multiple records to print in one line?

alt text http://img59.imageshack.us/img59/962/62737835.jpg This three columns are taken from 3 tables. In other words, these records are retrieved by joining 3 tables. It is basically a very simple time sheet that keeps track of shift starts time, lu

Rails 3 - Compare dates when creating a record

I have an invoice model with date_received, created_at and received_state. Upon record creation, I want to compare date_received and created_at to update the received_state. Specifically, if created_at is greater than 2 days past date_received, recei

How do I create multiple records for each day in a given quarter?

I have Shift model. --- !ruby/object:Shift attributes: id: starts_at: ends_at: I want to add singelton method to create shifts for each day in given quarter. class Shift def self.open_quarter(number, year) starts_at = "08:00" ends_at = "08:

Ember Data does not allow duplicate entries in multiple relationships

I have the following model: #order/model.coffee Order = DS.Model.extend { line_items: DS.hasMany 'product', {async: true} } At some point I want to add the some products to the order. I found that I can only add the product once, adding the same prod

Sharing models between Ember Apps with Ember Data 1.0.0-beta.4 (and Adapters and Serializers)

The site I'm building uses multiple Ember apps to manage different areas of the site. It used to be easy to share models definitions between apps. One app would define the models (i.e. App1.Product) and the other app (App2) could create them by calli

The index source on the lawn does not support multiple records

I tried creating multiple records in indexed-db but it won't allow me, example, nike and adidas objectStores var nike = Lawnchair({adapter:'indexed-db', name:'stores', record:'nike'},function(e){ console.log("nike store open"); this.save({id:1},

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK