Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Last active February 9, 2016 21:58
Show Gist options
  • Save gogogarrett/e0a1cec40999079a4f13 to your computer and use it in GitHub Desktop.
Save gogogarrett/e0a1cec40999079a4f13 to your computer and use it in GitHub Desktop.
didUpdateAttrs is not showing the correct oldAttrs. When I create a new associated object both the oldAttr and newAttr's both reflect the newly created Item in the value collection.
import Ember from 'ember';
export default Ember.Component.extend({
didUpdateAttrs: function(attrs) {
// attrs.newAttrs.ownedItems.value =>
// Class {canonicalState: Array[26], store: Class, relationship: ember$data$lib$system$relationships$state$has$many$$ManyRelationship, record: Class, currentState: Array[27]…}
// attrs.oldAttrs.ownedItems.value =>
// Class {canonicalState: Array[26], store: Class, relationship: ember$data$lib$system$relationships$state$has$many$$ManyRelationship, record: Class, currentState: Array[27]…}
// the oldAttrs and newAttrs both reflect the same ember data relationship after creating the new item in the purchase action
// I would have thought the oldAttrs would reflect the OLD assocation and newAttrs would reflect the NEW/CURRENT assocation
attrs.newAttrs.ownedItems.value == attrs.oldAttrs.ownedItems.value // true -- noo!!!
}
})
import Ember from 'ember';
export default Ember.Controller.extend({
purchasedItems: function() {
this.get('session.student.items')
}).property('session.student.items.[]'),
actions: {
purchase: function (item) {
this.store.createRecord('item', { code: item.id, student: this.get('session.student') }).save()
}
}
})
import DS from 'ember-data';
export default DS.Model.extend {
code: DS.attr("string")
student: DS.belongsTo("student") // belongs to student
}
import DS from 'ember-data';
export default DS.Model.extend {
name: DS.attr("string")
items: DS.hasMany("item") // has many items
}
{{caper-game purchase=(action 'purchase') ownedItems=purchasedItems}}
@Panman82
Copy link

Panman82 commented Feb 9, 2016

Did you start a case for this? I'm have the same problem...

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