-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Hello,
I ran into the situation where there were two models: "House" and "HouseGroup".
I fetched a list of houses using House.$search();, then took one of the records in that collection and $add-ed it to a HouseGroup (which has a hasMany relation to House).
The action fails silently because that house was already in the House collection.
This is the code in the library that causes it:
$add:` function(_obj, _idx) {
Utils.assert(_obj.$type && _obj.$type === this.$type, 'Collection $add expects record of the same $type');
return this.$action(function() {
if(_obj.$position === undefined) { // <--- Here's the problem.
if(_idx !== undefined) {
this.splice(_idx, 0, _obj);
} else {
this.push(_obj);
}
_obj.$position = true; // use true for now, keeping position updated can be expensive
this.$dispatch('after-add', [_obj]);
}
});
},
Proposed solution: allow records to be in multiple collections, or document why this is problematic and throw an exception instead of failing silently.
darkhelmet