Skip to content

hasMany relationship not updating from the belongsTo side. #116

@dweremeichik

Description

@dweremeichik

It appears that the hasMany relationships are not updating when a belongsTo record is created.
The two models i am using are:

export default Model.extend({
  name: DS.attr('string', {defaultValue: ""}),
  valueCents: DS.attr('number', {defaultValue: 0}),
  type: DS.attr('string', {defaultValue: ""}),
  discounts: DS.hasMany('discount')
});

and

export default Model.extend({
  triggerQuantity: DS.attr('number'),
  percentage: DS.attr('number'),
  item: DS.belongsTo('item')
});

I am attempting to add a discount to an existing item with the following code:

addDiscount(item){
      let discount = item.store.createRecord('discount',{
        item: item,
        triggerQuantity: 3,
        percentage: 3
      });
      discount.save();
    }

According to the ember docs, this should "just work". In the database, I can see that discount record has the id of the item that it was attached to. However the item record just contains an empty array, instead of an array with a reference to the discount record.

I am using:
Ember 2.4.1
ember-data 2.4.0
ember-pouch 3.1.1

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