oberhamsi
By: a guest | Jan 18th, 2010 | Syntax:
JavaScript | Size: 1.32 KB | Hits: 123 | Expires: Never
I showed that bug to hannes in RealLife. until then i gathered more info that hints towards a problem with the grouped collection being internally re-used when first removed (by emptying it) & then re-added within the same request.
i will try to explain with a simple code example:
example 1, this demonstrates the problem. the collection is first emptied, correctly dissappears but later when i add *one* element to it it re-appears with size() === 2:
> relations.get('foo').size()
1
> relations.remove(oldFooRelation)
> oldFooRelation.remove()
> relations.get('foo') === undefined
true
> relations.add(newFooRelation)
> relations.get('foo').size()
2 /// !!! it should be 1.
not only the size() is wrong. i can also list() over the 2 items.
example 2, this works because the grouped collection 'foo' is never empty:
> relations.get('foo').size()
5
> relations.remove(oldFooRelation)
> relations.get('foo').size()
4
> relations.add(newFooRelation)
> relations.get('foo').size()
5 // correct
my collection looks like this.
relations = collection (Relation)
relations.accessname = REL_DST_ID
relations.local.1 = $id
relations.foreign.1 = REL_SRC_ID
relations.local.2 = $prototype
relations.foreign.2 = REL_SRC_PROTOTYPE
relations.group = REL_TYPE