emberjs/data — Issue #122: Inputs bound to newly created models fail
Author: sandstrom
Created: 2012-02-27 08:36:38+00:00
State: open

An {{#each}} is iterating over a couple of models. When I add another model to the collection the view is updated, but the new model can't modified using the input fields (i.e. newModel.set('myProp', 'foo') fails). It seems like there is a proxy object (for the model instance) in the view, and that this proxy is in a perpetual loading state.

I've nailed down a test case which outlines the problem (the code is also below):
http://jsfiddle.net/BWDRr/4/

*Not sure if this is a bug, it could also be that I've misunderstood how the library is supposed to be used.*

**handlebars:**

**code:**

window.EmberApp = Em.Application.create()

EmberApp.store = DS.Store.create({
adapter: DS.RESTAdapter.create({ bulkCommit: false })
})

EmberApp.Country = DS.Model.extend({
name: DS.attr('string')
population: DS.attr('string')
})

EmberApp.User = DS.Model.extend({
countries: DS.hasMany(EmberApp.Country, { embedded:true })
})

EmberApp.MyView = Em.View.extend({

user: EmberApp.store.createRecord(EmberApp.User, {
countries: [{ id: "de", name: "germany", population:"200" }]
})

addCountry: ->
console.log("addCountry()")
newCountry = EmberApp.store.createRecord(EmberApp.Country, {})
@get("user").get("countries").addObject(newCountry)
console.log "newCountry.isLoaded: #{newCountry.get('isLoaded')}"
console.log newCountry

printData: ->
console.log("printData")
console.log @get("user").get("data")
console.log @get("user").get("countries").map( (i) -> i.get("data") )

})

EmberApp.CountryView = Em.View.extend({
tagName: "li"

init: ->
console.log "CountryView initialized: #{@get('elementId')}"
self = this
peek_ = -> self.peek.call(self)
setTimeout(peek_, 1000)
@_super()

peek: ->
console.log "peeking at most recent country"
console.log "country.isLoaded: #{@get('content').get('isLoaded')}"
console.log @get("content")

})