Circular Relation Issue

Long time lurker first time poster.

I've been working on an Enyo 2.7 application and have been attempting to make use of the RelationalModel kind. I've spent substantial time looking at the very small number of examples available, and have come to the conclusion that I must be missing something obvious.

The link below will take you to a jsFiddle with an example that illustrates the issue I'm having with what I'm calling "circular relations". Things mostly work, and I expect that the issue is related to the subkind declaration order. I'm a relative JS novice and have been unable to come up with a way to solve this issue on my own.

https://jsfiddle.net/kLobmbx6/

Can someone tell me what I am missing? Should my example actually work? Have I set something up incorrectly?

Any insight would be greatly appreciated.

Thank you

Comments

  • There is a reference issue in that you've included Location in your relations list for User but that variable isn't defined until later. I added User.prototype.relations[0].model = Location; after Location was defined but ran into new errors.

    I'll look at this some more but please investigate more on your side as well!
  • I was reasonably certain that this was the issue.

    Your approach is very similar to the method that I was trying to use to resolve the issue and I thought that I must be missing a more obvious mechanism for resolving the ordering issue.

    I haven't found anything that works yet, but will continue to pursue the approach.
  • When using the 'User.prototype.relations[0].model = Location' approach, it results in an error caused by an infinite call stack (I'm assuming because now there is a cycle amongst the relations).

    Some experimentation and tracing of code led me to change isOwner to false. That fixes the error and results in the correct behavior for the toMany relations.

    Unfortunately, I am now unable to retrieve the owner entry from a Location record (it's a toOne relation).

    I have updated the JSFiddle to reflect this new situation.

    https://jsfiddle.net/kLobmbx6/
  • Unfortunately, I don't have a lot of depth in the RelationalModel code so I can't say for sure that circular dependencies should work. Hoping someone from the community has had some experience in this and can contribute.
  • Just a clarification.

    The circular dependency is working (at least in this example). Something that was working before I set isOwner to false (a single toOne Relation) is no longer working.
Sign In or Register to comment.