javascript - model.save() timing issue in ember-data with belongsTo relationship -


i have 2 models (source , problem) , saving instance relation other when click triggered through ui.

app.sourcescontroller = ember.arraycontroller.extend   actions:     addproblem: (source) ->       problem = @store.createrecord('problem',         detectedon: new date(),         source: source       )       problem.save().then (problem) ->           # handle success         ,(e) ->           # handle error       false 

i source present when inside addproblem action, when client serializes model , sends request, detectedon attribute present, source_id found.

now, here interesting part.

when wrap save code in settimeout, both detectedon , source_id sent server:

app.sourcescontroller = ember.arraycontroller.extend   actions:     addproblem: (source) ->       problem = @store.createrecord('problem',         detectedon: new date(),         source: source       )       settimeout ->         problem.save().then (problem) ->             # handle success           ,(e) ->             # handle error         , 1       false 

it seems me it's timing issue within ember's cycle, or perhaps missing something?

how can rid of settimeout? should not doing every time save.

i solved setting inverse relationship manually when resolving promise.the following should work you:

app.sourcescontroller = ember.arraycontroller.extend   actions:     addproblem: (source) ->       problem = @store.createrecord('problem',         detectedon: new date(),         source: source       )       problem.save().then (problem) ->           source.get('problems').addobject(problem)         ,(e) ->           # handle error       false 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -