Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:18:33+00:00 2026-06-16T01:18:33+00:00

Background Recently Tom Dale announced that Embedded loading is now back!. However it only

  • 0

Background

Recently Tom Dale announced that “Embedded loading is now back!”. However it only appears to be fully supported for the loading scenario. It is unclear if serializing embedded associations is still under development, or if users are expected to implement it themselves by building a custom serializer.

Requirements

The JSON for my embedded association looks like this:

{
  inputs: [
    {
      id: 1,
      name: "Favorite Color",
      type: "SelectInput",
      options: {
        choices: [ 'red', 'green', 'yellow' ]
      }
    },   
    {
      id: 2,
      name: "email",
      type: "TextInput",
      options: {}
    }
  ]
}

I believe the “ember way” to represent this is to build a custom serializer that will convert my JSON to models like:

App.Choice = DS.Model.extend({
  name: DS.attr( 'string' ),
  input: DS.belongsTo( 'App.Input' )
});

App.Input = DS.Model.extend({
  name: DS.attr( 'string' ),
  type: DS.attr( 'string' ),
  choices: DS.hasMany( 'App.Choice' )
});

Attempted Solution

The following solution mostly works, however it feels like I must be “doing it wrong” because I’m having to reverse engineer and subclass so much code.

Customizer.MyRESTAdapter = DS.RESTAdapter.extend({
  dirtyRecordsForAttributeChange: function(dirtySet, record, attributeName, newValue, oldValue) {
    if(record.constructor === Customizer.Choice) {
      if(newValue === oldValue) { return; }

      var input = null;
      if (attributeName == 'name') {
        input = record.get('input');
      }
      else if(attributeName == 'input') {
        input = newValue;
      }
      if( input ) {
        dirtySet.add( input );
      }
    }
    else {
      this._super(dirtySet, record, attributeName, newValue, oldValue);
    }
  },

  dirtyRecordsForBelongsToChange: function(dirtySet, child, relationship) {
    if(child.constructor === Customizer.Choice) {
      var input = child.get( 'input' );
      if( input ) {
        dirtySet.add( input );
      }
    }
    else {
      this._super(dirtySet, child, relationship);
    }
  },

  dirtyRecordsForHasManyChange: function(dirtySet, parent, relationship) {
    this._super(dirtySet, parent, relationship);
  }
});

Customizer.MyRESTSerializer = DS.RESTSerializer.extend({
  init: function() {
    this._super();
    this.mappings.set( 'Customizer.Input', { choices: { embedded: 'load' } } );
  },

  extractEmbeddedHasMany: function(type, hash, key) {
    if(type == Customizer.Input) {
      if(!(hash['options'] && hash['options']['choices'])) { return null; }

      var choices = [];
      hash['options']['choices'].forEach(function(choice, i){
        var choiceId = hash['id'] + '_' + i;
        var inputId = hash['id'];
        choices[i] = { id: choiceId, input_id: inputId, name: choice };
      });
      return choices;
    }

    return this._super(type, hash, key);
  },

  addHasMany: function(data, record, key, relationship) {
    this._super(data, record, key, relationship);

    if( key === 'choices' ) {
      var choices = record.get('choices').map(function( choice ){
        return choice.get( 'name' );
      });
      data['options'] = data['options'] || {};
      data['options']['choices'] = choices;
    }
  }

});

Customizer.store = DS.Store.create({
  revision: 10,
  adapter: Customizer.MyRESTAdapter.create({
    namespace: 'api/v1',
    bulkCommit: false,
    serializer: Customizer.MyRESTSerializer
  })
})

Request For Feedback

  • Is this the right path?
  • Is the ember team actively working on a better way to do this?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:18:35+00:00Added an answer on June 16, 2026 at 1:18 am

    Check out the embedded-records branch of ember-data:
    https://github.com/emberjs/data/commits/embedded-records

    In particular, see this commit for saving embedded data:
    https://github.com/emberjs/data/commit/0abd3b965c50dfeb23bd8ff50751825482050e68

    Full support for embedded records is right around the corner 🙂

    Update

    Embedded records branch was merged into master on 12/28/2012:

    https://github.com/emberjs/data/commit/b5d7c478e79aa9706e0196b8769b7ef67bb26fc4

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from a Powerbuilder background. I was recently announced that we change development
Background: I have a Java application that many programming clients interface with. Recently, a
Is there a way to make sure that a certain background image recently updated
Background I have an app that I recently updated to Rails 3.2.1 (from Rails
I recently tried applying a gradient background to a webpage using only CSS3. while
Ok, I recently implemented a background worker to perform saving and loading of data.
I have a PHP script that launches another script in the background. Recently my
Background info I recently handed in an assigment for my class on algorithms and
Background info: I've recently decided to take on a project of making a social
I recently got into Java. I have a background in dynamic languages and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.