function(record, options) {
    var json = {};

    if (options && options.includeId) {
      var id = get(record, 'id');

      if (id) {
        json[get(this, 'primaryKey')] = id;
      }
    }

    record.eachAttribute(function(key, attribute) {
      this.serializeAttribute(record, json, key, attribute);
    }, this);

    record.eachRelationship(function(key, relationship) {
      if (relationship.kind === 'belongsTo') {
        this.serializeBelongsTo(record, json, relationship);
      } else if (relationship.kind === 'hasMany') {
        this.serializeHasMany(record, json, relationship);
      }
    }, this);

    return json;
  }
function(record, options) {
    var json = {};

    if (options && options.includeId) {
      var id = get(record, 'id');

      if (id) {
        json[get(this, 'primaryKey')] = id;
      }
    }

    record.eachAttribute(function(key, attribute) {
      this.serializeAttribute(record, json, key, attribute);
    }, this);

    record.eachRelationship(function(key, relationship) {
      if (relationship.kind === 'belongsTo') {
        this.serializeBelongsTo(record, json, relationship);
      } else if (relationship.kind === 'hasMany') {
        this.serializeHasMany(record, json, relationship);
      }
    }, this);

    return json;
  }
function ( record , options ) { var json = { } ; if ( options && options . includeId ) { var id = get ( record , 'id' ) ; if ( id ) { json [ get ( this , 'primaryKey' ) ] = id ; } } record . eachAttribute ( function ( key , attribute ) { this . serializeAttribute ( record , json , key , attribute ) ; } , this ) ; record . eachRelationship ( function ( key , relationship ) { if ( relationship . kind === 'belongsTo' ) { this . serializeBelongsTo ( record , json , relationship ) ; } else if ( relationship . kind === 'hasMany' ) { this . serializeHasMany ( record , json , relationship ) ; } } , this ) ; return json ; }
SERIALIZE 
Called when a record is saved in order to convert the
record into JSON.

By default, it creates a JSON object with a key for
each attribute and belongsTo relationship.

For example, consider this model:

```javascript
App.Comment = DS.Model.extend({
title: DS.attr(),
body: DS.attr(),

author: DS.belongsTo('user')
});
```

The default serialization would create a JSON object like:

```javascript
{
"title": "Rails is unagi",
"body": "Rails? Omakase? O_O",
"author": 12
}
```

By default, attributes are passed through as-is, unless
you specified an attribute type (`DS.attr('date')`). If
you specify a transform, the JavaScript value will be
serialized when inserted into the JSON hash.

By default, belongs-to relationships are converted into
IDs when inserted into the JSON hash.

## IDs

`serialize` takes an options hash with a single option:
`includeId`. If this option is `true`, `serialize` will,
by default include the ID in the JSON object it builds.

The adapter passes in `includeId: true` when serializing
a record for `createRecord`, but not for `updateRecord`.

## Customization

Your server may expect a different JSON format than the
built-in serialization format.

In that case, you can implement `serialize` yourself and
return a JSON hash of your choosing.

```javascript
App.PostSerializer = DS.JSONSerializer.extend({
serialize: function(post, options) {
var json = {
POST_TTL: post.get('title'),
POST_BDY: post.get('body'),
POST_CMS: post.get('comments').mapProperty('id')
}

if (options.includeId) {
json.POST_ID_ = post.get('id');
}

return json;
}
});
```

## Customizing an App-Wide Serializer

If you want to define a serializer for your entire
application, you'll probably want to use `eachAttribute`
and `eachRelationship` on the record.

```javascript
App.ApplicationSerializer = DS.JSONSerializer.extend({
serialize: function(record, options) {
var json = {};

record.eachAttribute(function(name) {
json[serverAttributeName(name)] = record.get(name);
})

record.eachRelationship(function(name, relationship) {
if (relationship.kind === 'hasMany') {
json[serverHasManyName(name)] = record.get(name).mapBy('id');
}
});

if (options.includeId) {
json.ID_ = record.get('id');
}

return json;
}
});

function serverAttributeName(attribute) {
return attribute.underscore().toUpperCase();
}

function serverHasManyName(name) {
return serverAttributeName(name.singularize()) + "_IDS";
}
```

This serializer will generate JSON that looks like this:

```javascript
{
"TITLE": "Rails is omakase",
"BODY": "Yep. Omakase.",
"COMMENT_IDS": [ 1, 2, 3 ]
}
```

## Tweaking the Default JSON

If you just want to do some small tweaks on the default JSON,
you can call super first and make the tweaks on the returned
JSON.

```javascript
App.PostSerializer = DS.JSONSerializer.extend({
serialize: function(record, options) {
var json = this._super.apply(this, arguments);

json.subject = json.title;
delete json.title;

return json;
}
});
```

@method serialize
@param {subclass of DS.Model} record
@param {Object} options
@return {Object} json
SERIALIZE Called when a record is saved in order to convert the record into JSON .