Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master branch not saving hasMany relationship #287

Closed
sir-dunxalot opened this issue Jul 20, 2015 · 8 comments
Closed

master branch not saving hasMany relationship #287

sir-dunxalot opened this issue Jul 20, 2015 · 8 comments

Comments

@sir-dunxalot
Copy link

I have a hasMany relationship on a model:

// models/feature.js

export default DS.Model.extend({
  stages: DS.hasMany('stage', {
    async: true
  }),
});
// models/stage.js
export default DS.Model.extend({
  feature: DS.belongsTo('feature', {
    async: true
  }),
});

I am creating stages and setting them on a feature. The stages array exists on the feature client-side. However, it is not persisted to the Firebase DB.

This is how I am saving the models:

  save() {
    this.get('model').save().then(function(feature) {
      feature.get('stages').forEach(function(stage) {
        stage.save();
      });
    });
  },

Here is how the feature model appears in the Firebase DB:

image

One would expect an array of stages to be persisted to the feature model.

The stage model persists as expected:

image

Is there something obviously wrong here or could this be a bug on master branch?

  • Ember 1.13.2
  • Ember Data 1.13.5
  • Emberfire master branch
@tmayr
Copy link
Contributor

tmayr commented Jul 20, 2015

Having the same issues, seems like updateRecords isnt serializing the records properly.

Might be related to emberjs/data#3550 ?

@tstirrat
Copy link
Contributor

Thanks for the report, will do some testing and work out what's wrong.

@tstirrat tstirrat mentioned this issue Jul 20, 2015
9 tasks
@sir-dunxalot
Copy link
Author

Thanks, Tim. Also, to confirm the error is not existent with Ember fire 1.4.7 and ED beta.18.

sir-dunxalot pushed a commit to sir-dunxalot/trailblazer-old that referenced this issue Jul 21, 2015
@tstirrat
Copy link
Contributor

ok, I figured out what this is.

It's ember-data JSONSerializer's _shouldSerializeHasMany returns false on manyToOne relationships

i.e. when a hasMany has a companion belongsTo relationship the JSONSerializer prefers to only save the belongsTo side.

@sir-dunxalot
Copy link
Author

Thanks for looking into it, Tim. is there something we should do in apps to mitigate this or is it likely to be solved by either ED or Emberfire in an upcoming release?

@tstirrat
Copy link
Contributor

I have a fix ready, just creating a breaking test to ensure this issue doesn't pop up again.

@tstirrat
Copy link
Contributor

Let me know if an updated master fixes your issue.

Reopen this issue if you still have problems :)

@sir-dunxalot
Copy link
Author

Looks like that fixed it. Thanks a lot!

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

No branches or pull requests

3 participants