home
  • Blog
1.12
  • Getting Started
  • Concepts
  • The Object Model
  • Application
  • Templates
  • Routing
  • Components
  • Controllers
  • Models
    • Introduction
    • Defining Models
    • Creating and Deleting Records
    • Pushing Records into the Store
    • Persisting Records
    • Finding Records
    • Working with Records
    • The Rest Adapter
    • Connecting to an HTTP Server
    • Handling Metadata
    • Customizing Adapters
    • Frequently Asked Questions
  • Views
  • Enumerables
  • Testing
  • Configuring Ember.js
  • Ember Inspector
  • Cookbook
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.12.0.
Go to v5.0.0

Working with Records

Edit pencil

Modifying Attributes

Once a record has been loaded, you can begin making changes to its attributes. Attributes behave just like normal properties in Ember.js objects. Making changes is as simple as setting the attribute you want to change:

var tyrion = this.store.find('person', 1);
// ...after the record has loaded
tyrion.set('firstName', "Yollo");

All of the Ember.js conveniences are available for modifying attributes. For example, you can use Ember.Object's incrementProperty helper:

person.incrementProperty('age'); // Happy birthday!

You can tell if a record has outstanding changes that have not yet been saved by checking its isDirty property. You can also see what parts of the record were changed and what the original value was using the changedAttributes function. changedAttributes returns an object, whose keys are the changed properties and values are an array of values [oldValue, newValue].

person.get('isAdmin');      //=> false
person.get('isDirty');      //=> false
person.set('isAdmin', true);
person.get('isDirty');      //=> true
person.changedAttributes(); //=> { isAdmin: [false, true] }

At this point, you can either persist your changes via save() or you can rollback your changes. Calling rollback() reverts all the changedAttributes to their original value.

person.get('isDirty');      //=> true
person.changedAttributes(); //=> { isAdmin: [false, true] }

person.rollback();

person.get('isDirty');      //=> false
person.get('isAdmin');      //=> false
person.changedAttributes(); //=> {}
left arrow
Finding Records
The Rest Adapter
right arrow
On this page

  • Modifying Attributes
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2023 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue