Last active
February 9, 2016 21:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!! | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend { | |
code: DS.attr("string") | |
student: DS.belongsTo("student") // belongs to student | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend { | |
name: DS.attr("string") | |
items: DS.hasMany("item") // has many items | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you start a case for this? I'm have the same problem...