# Model Declaration: false vs DS.attr('boolean', {defaultValue: false})

**URL:** <https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860>\
**Category:** Ember Data\
**Created:** [July 9, 2014, 12:21am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860 "2014-07-09T00:21:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![duereg](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/duereg/32/15661_2.png) [@duereg](https://discuss.emberjs.com/u/duereg)\
**Post date:** [July 9, 2014, 12:21am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/1 "2014-07-09T00:21:11Z")

</div>

I am working with some older Ember.Data code, and I came across a model like this:

```javascript
App.MyFancyModel = DS.Model.extend({
  isSelected: false,
  isSomethingElse: DS.attr('boolean', {defaultValue: false})
});

```

I thought this code was a bit strange, and then went and played with it a bit:

```javascript
aFancyModel.get('isSelected'); //returns false
aFancyModel.set('isSelected', true); 
aFancyModel.get('isSelected'); //returns true
aFancyModel.get('isSomethingElse'); //returns false
aFancyModel.set('isSomethingElse', true); 
aFancyModel.get('isSomethingElse'); //returns true

```

I got identical behavior from the two properties. Then, I tried this:

```javascript
aFancyModel.set('isSelected', true); 
aFancyModel.get('isDirty'); //RETURNS FALSE
aFancyModel.set('isSomethingElse', true); 
aFancyModel.get('isDirty'); //RETURNS TRUE!!!

```

So I guess my question is this: is this the expected behavior? I can’t find any documentation on setting boolean values directly on the model like this anywhere in the Ember.Data docs.

---

<div class="post-metadata">

**Author:** ![ulisesrmzroche](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ulisesrmzroche/32/11317_2.png) [@ulisesrmzroche](https://discuss.emberjs.com/u/ulisesrmzroche)\
**Post date:** [July 9, 2014, 1:32am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/2 "2014-07-09T01:32:38Z")

</div>

One’s just a plain boolean, the other one is actually a DS.attr(), so bindings will be setup correctly. That’s why the latter dirties the model.

---

<div class="post-metadata">

**Author:** ![duereg](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/duereg/32/15661_2.png) [@duereg](https://discuss.emberjs.com/u/duereg)\
**Post date:** [July 9, 2014, 4:44pm UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/3 "2014-07-09T16:44:03Z")

</div>

> [@ulisesrmzroche](#):
>
> DS

Using a boolean instead of DS.attr(‘boolean’) in previous versions of ember.data dirtied the model. I’ve recently upgraded to ember.data 1.0.0-beta.8 and I’ve noticed this behavior change.

Trying to figure out if this is by design or a bug.

---

<div class="post-metadata">

**Author:** ![ulisesrmzroche](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ulisesrmzroche/32/11317_2.png) [@ulisesrmzroche](https://discuss.emberjs.com/u/ulisesrmzroche)\
**Post date:** [July 10, 2014, 1:20am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/4 "2014-07-10T01:20:37Z")

</div>

oh! Yeah, that makes sense. How old is the Ember Data you’re using? You may also want to look into the .find() changes if you’re coming from a really old version.

---

<div class="post-metadata">

**Author:** ![ulisesrmzroche](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ulisesrmzroche/32/11317_2.png) [@ulisesrmzroche](https://discuss.emberjs.com/u/ulisesrmzroche)\
**Post date:** [July 10, 2014, 1:21am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/5 "2014-07-10T01:21:47Z")

</div>

The 2nd version is better practice, though.

---

<div class="post-metadata">

**Author:** ![nandosan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nandosan/32/267_2.png) [@nandosan](https://discuss.emberjs.com/u/nandosan)\
**Post date:** [July 10, 2014, 6:08am UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/6 "2014-07-10T06:08:44Z")

</div>

Design, of course.

Not to serialize attributes different from DS.attr() allows you to have local properties on your models that does not affect the communication with the server.

Say, a computed property calculated over a bunch of other attributes that make sense on the client side, but there is no need for the server to store or bother about.

---

<div class="post-metadata">

**Author:** ![duereg](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/duereg/32/15661_2.png) [@duereg](https://discuss.emberjs.com/u/duereg)\
**Post date:** [July 11, 2014, 4:44pm UTC](https://discuss.emberjs.com/t/model-declaration-false-vs-ds-attr-boolean-defaultvalue-false/5860/7 "2014-07-11T16:44:43Z")

</div>

Makes sense. Just wanted to verify the behavior. Thanks!
