Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Belongs_to Data Goes Null While Saving

$
0
0

@Harun_Tuncay wrote:

Hi everyone.I am building a toy app and wanted to work with a simple 1:many relationship.
My car model "hasMany comments" & my comments "belongsTo car".I want a comment to be created from cars/car route.So i didn't created a route for comments/new.For a quick trial i have added a button that has "saveComment" action.

<button type="submit" {{action 'saveComment' model}}>Submit</button>

!!! I am passing the model because in my action i want to read it's id and set it to comments car_id.

And here is the correspanding route file

  model(params){
   return this.store.findRecord('car', params.car_id);
  },
 actions: {
  saveComment(model){
     let car = this.store.peekRecord('car', model.id),
     let newComment = this.store.createRecord('comment'{
            car: car,
            body: 'Some filler text! ',
        });
   car.get('comments').pushObject('newComment');
   newComment.save();
  }

The problem is, my (let the route be cars/10) current template includes the newly generated comment with the proper body, however when i inspect it, belongsTo relationship looks empty.Since car_id goes null, after a reload, new generated comments disappeares.(not from the database tho, it is saved succesfully without a car relationship).What should i do to get this comments.car saved? TIA

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles