jaydata icon indicating copy to clipboard operation
jaydata copied to clipboard

Recursive Complex Types

Open jpattersonz opened this issue 7 years ago • 3 comments

Deal with recursive data types in the model binder config compiler and query builder. If the type is already on the query builder stack, then skip it.

jpattersonz avatar Apr 17 '17 17:04 jpattersonz

Thanks for this, I ran into this issue a few days after your PR. however, I did need to make a modification for my purposes as your solution only allowed for deserialization to 1 level deep. Any additional child entities were ignored. This is the change I made, it allows 10 instances of the elementType to be present before it flags it as existing. stackContainsType: function (elementType) { //allow the stack to contain 10 of any given type to allow for deeper, but not infinite recursion. var typeCount = this._binderConfigPropertyStack .map(p => p.$type) .filter(function (x) { return x == elementType }) .length; return typeCount > 10;

lance-wynn-cireson avatar Apr 28 '17 16:04 lance-wynn-cireson

Interesting, it sounds like the logic in stackContainsType has a flaw. My intent was to not recurse into a type which we already processed, but I suppose the logic should really be that we don't recurse into a Property that we have already processed. If I get some time, I'll take a look at this. Perhaps one of the core JayData developers can provide more insight.

jpattersonz avatar Apr 28 '17 19:04 jpattersonz

I think the problem may be that the queryBuilder builds out the graph first, and then applies the incoming data, which is why it gets a infinite recursion if a type repeats itself, and also why it stops resolving child elements after the end depth of the queryBuilder graph is reached.

lance-wynn-cireson avatar Apr 28 '17 19:04 lance-wynn-cireson