You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DEBUG: -------------------------------
DEBUG: Ember : 2.6.0
DEBUG: Ember Data : 2.6.1
DEBUG: Firebase : 3.0.5
DEBUG: EmberFire : 2.0.1
DEBUG: jQuery : 2.2.2
DEBUG: -------------------------------
Description
When working with relationships that have hasMany and belongsTo relationships, it seems EmberFire does not automatically update a parent model's hasMany reference when a child record with belongsTo is added. For example, if I have two models framework and question, where a question has a belongsTo relationship to a framework and a framework has a hasMany relationship to it's questions. Please see the models below:
When a new question is added and has a valid entry for frameworkbelongsTo, it would be expected that on newQuestion.save() for example, both question model would be updated with the frameworkbelongsTo entry AND the framework model would be updated automatically with the revised hasMany list of questions in the framework model.
Actual behavior
Unfortunately, when a new question is added, there seems to be no update to the framework model and therefore, the questionshasMany list is not updated. After investigating the emberfire/app/adapters/firebase.js file, it seems there is no call on a belongsTo relationship that would trigger the save of the "parent" model.
I have found however that the following work around does solve the problem:
If a newQuestion is added to the local store and saved in Firebase, the next time I call a framework.save() the entire questionshasMany field was updated correctly. Adding this small framework.save() after saving a to the question model has solved my problem, however it seems to be a work around in my opinion.
But maybe this bug is a feature, and I don't realize the downfalls to doing this automatically. Thoughts are welcomed as I'm quite new to Ember and EmberFire. Thanks for the great library regardless!
The text was updated successfully, but these errors were encountered:
When it comes to async relationships it's by design. These situations need to be accounted for by the developer. Unfortunately, it's not simple to infer what the developer needs in these situations.
Consider some examples:
You have pending changes to the parent model (frameworks), you call question1.save(). Should all the pending changes on the parent be saved, or just the hasMany links? Saving the parent could produce unexpected results for some developers.
You're editing the parent, you add a child, we go ahead and update the parent. Then you decide to cancel the parent changes with parent.rollback(). Should we revert the parent.children change too? only the developer truly knows what should happen here.
So in your example, the workaround you gave is what I do, and most others do:
Embedded records are a little bit different. With these, if you save the parent, we can be more sure that saving all children is ok, given that everything lives under the same structure in the DB.
Version Information
Description
When working with relationships that have hasMany and belongsTo relationships, it seems EmberFire does not automatically update a parent model's hasMany reference when a child record with belongsTo is added. For example, if I have two models
framework
andquestion
, where aquestion
has abelongsTo
relationship to aframework
and aframework
has ahasMany
relationship to it'squestion
s. Please see the models below:Expected behavior
When a new
question
is added and has a valid entry forframework
belongsTo
, it would be expected that onnewQuestion.save()
for example, bothquestion
model would be updated with theframework
belongsTo
entry AND theframework
model would be updated automatically with the revisedhasMany
list ofquestions
in theframework
model.Actual behavior
Unfortunately, when a new
question
is added, there seems to be no update to theframework
model and therefore, thequestions
hasMany
list is not updated. After investigating theemberfire/app/adapters/firebase.js
file, it seems there is no call on abelongsTo
relationship that would trigger the save of the "parent" model.I have found however that the following work around does solve the problem:
If a newQuestion is added to the local store and saved in Firebase, the next time I call a
framework.save()
the entirequestions
hasMany
field was updated correctly. Adding this smallframework.save()
after saving a to thequestion
model has solved my problem, however it seems to be a work around in my opinion.But maybe this bug is a feature, and I don't realize the downfalls to doing this automatically. Thoughts are welcomed as I'm quite new to Ember and EmberFire. Thanks for the great library regardless!
The text was updated successfully, but these errors were encountered: