Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
This repository was archived by the owner on May 19, 2025. It is now read-only.

Embedded hasMany not saving #354

Open

Description

@jembezmamy

My hasMany relationship doesn't get saved when I use embedded records.

// app/models/schedule.js
import DS from 'ember-data';

export default DS.Model.extend({
  interval:     DS.attr("number", {defaultValue: 1}),
  duties:       DS.hasMany('duty', { async: false })
});
// app/serializers/schedule.js
import FirebaseSerializer from 'emberfire/serializers/firebase';

export default FirebaseSerializer.extend({
  attrs: {
    duties: { embedded: 'always' }
  }
});

Then I run in console:

schedule = store.createRecord("schedule");
schedule.get("duties").createRecord();
schedule.save();

Then I get in firebase:

{
  "duties" : {
    "-K8JihEkTfYlEmIWGlTS" : {
      "schedule" : "-K8JidJrYtqLkLDP1k14"
    }
  },
  "schedules" : {
    "-K8JidJrYtqLkLDP1k14" : {
      "interval": 1
    }
  }
}

So as can you see, duty record is created and even assigned to the schedule, but schedule record has no duties assigned... Then, when I try to load this schedule in Ember, it also has no duties. Am I doing something wrong?

I use ember 2.1.0, ember-data 2.1.0 and ember-fire 1.6.3.

Activity

  1. tstirrat commented on Jan 21, 2016

    @tstirrat
    Contributor

    it looks like you are doing everything correctly. I wonder if it's related to the inverse relationship. Can you remove duty's link back to the interval and see if that fixes it?

    Otherwise, I'd like to get a minimal example so I can debug into it.

  2. jembezmamy commented on Jan 21, 2016

    @jembezmamy
    Author

    It works! Great. But to be frank I need this inverse... Is there any workaround for this situation?

  3. tstirrat commented on Jan 21, 2016

    @tstirrat
    Contributor

    Thanks for reporting back. It was a total guess... now I need to work out why this is the case...

  4. tstirrat commented on Jan 21, 2016

    @tstirrat
    Contributor

    can you try the branch in #337 to see if using atomic saves + the ember-data EmbeddedRecordsMixin helps?

  5. jembezmamy commented on Feb 1, 2016

    @jembezmamy
    Author

    Yes, it works! Thanks.

  6. tstirrat commented on Feb 1, 2016

    @tstirrat
    Contributor

    Great, that branch will be EmberFire 2.0. I will make a release this week

  7. AndersDJohnson commented on Feb 3, 2016

    @AndersDJohnson
    Contributor

    @tstirrat Great news if Emberfire 2.0 is coming this week!

  8. hussfelt commented on Feb 11, 2016

    @hussfelt

    @tstirrat release on the way? :)

  9. tstirrat commented on Feb 11, 2016

    @tstirrat
    Contributor

    @hussfelt if you follow the discussion in #337 you'll see that we are not planning to merge it anymore.

  10. tstirrat commented on Feb 11, 2016

    @tstirrat
    Contributor

    There is more discussion on underlying ember-data bugs in #365, too

  11. hussfelt commented on Feb 12, 2016

    @hussfelt

    @tstirrat Sorry, I hijacked this issue just to get info on a new release. :) My bad!

    Thanks for a great service!

  12. tstirrat commented on Feb 12, 2016

    @tstirrat
    Contributor

    No problem 😸

  13. bhernez commented on Jan 27, 2019

    @bhernez

    Hi!

    I know it is a very old issue, but I'm experiencing the same problem. I tried to do what @jembezmamy did (b/c he said it worked) but in my case it didn't. I'm following the instructions in the guides, and my models are:

    // app/models/product.js
    import DS from 'ember-data';
    import { all } from 'rsvp';
    
    export default DS.Model.extend({
      prices: DS.hasMany('price', { async: false, inverse: null }),
    });
    
    // app/serializers/product.js
    import FirebaseSerializer from 'emberfire/serializers/firebase';
    
    export default FirebaseSerializer.extend({
      attrs: {
        prices: { embedded: 'always' }
      }
    });
    
    // app/models/price.js
    import DS from 'ember-data';
    export default DS.Model.extend({
      // product: DS.belongsTo('product', {inverse: 'prices'})
    });
    

    Any idea or suggestion?

    I use Ember 3.5.1, Ember Data 3.5.2 and EmberFire 2.0.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions