Setting boolean field not persisting in record

I have the following code:

var id = model.get('id');'listingEvent', id)
            var toggle = !le.get('currentUserAttending');
            le.set('currentUserAttending', toggle);

No matter what toggle ends up being false is always persisted to the server. Even if I hard code it as true!

Here is my model:

import DS from 'ember-data';

export default DS.Model.extend({
  	slug: DS.attr('string'),
  	currentUserAttending: DS.attr('boolean'),
  	location: DS.belongsTo('location'),
  	artists: DS.hasMany('artist', {async:true}),
  	usersAttending: DS.hasMany('userAccount', {async:true})

Can anyone shed some light on this because I am genuinely perplexed!

Anyone? Surely I am missing something obvious?

1 Like

Basically based on what the docs say - this should work - so I am assuming it is a bug in ember data - a pretty fundamental one at that as this is probably one of the most basic use cases!


DEBUG: Ember      : 1.7.0 vendor.js:27630
DEBUG: Ember Data : 1.0.0-beta.10 vendor.js:27630
DEBUG: Handlebars : 1.3.0 vendor.js:27630
DEBUG: jQuery     : 1.11.1

Gotten a little bit further with this

If I don’t call .save the record correctly reflects the changes. Calling .save sends the old state to the server which responds with the old state and thus resets the copy in ember-data store. should send the updated record surely?

Am I seriously the only person getting this?!?!

Try to reproduce it in a with the same versions of the libs that you are using. This might be an issue with how your backend returns the data upon save.

It’s not that. Ember is sending the original record not the updated one.

There have been several issues with Ember-Data and Ember, I think 10 and 11 have to be used with ember 1.8.x

Aha, ok, I will try this in the am then. Thank you, I’ll let you know how I get on.

This didn’t work I am afraid - I am trying to get a JSBin together but can’t get anything to work there either!

Is your server providing the correct response? If your server always return true or false for the Boolean flag, after the response came back, it will automatically overwrite the flag. I’ve gotten burned by this a few times.

This was actually my balls up.

The reason I thought it was sending the wrong data to the server was because in the preview pane in Chrome it shows something else - but not the data that is being sent. That completely screwed me up. Once I had figured that out I realised it was sending the correct data and because the data coming back from the server wasn’t formatted correctly it was being rejected by ember and reverted…