Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relations as persisted derived fields #413

Closed
stephenh opened this issue Sep 7, 2022 · 2 comments
Closed

Support relations as persisted derived fields #413

stephenh opened this issue Sep 7, 2022 · 2 comments
Labels
enhancement New feature or request hack day seems doable in a hack day

Comments

@stephenh
Copy link
Collaborator

stephenh commented Sep 7, 2022

No description provided.

@stephenh
Copy link
Collaborator Author

@chr1sjf0x I did a spike of this in #416 ; I got maybe 80% of the "recalc + save to the db" mechanism done, but then realized that these will be need to be worked into load hints.

I.e. I made a Author.favoriteBook: Book that is calculated from the Author.books collection.

When someone does em.load(Author, "a:1"), we know "the favorite book is b:1", but we haven't actually loaded the Book entity yet, i.e. just like any other FK. So even though the PersistedDerivedProperty.get method is available:

const a = await em.load(Author, "a:1");
console.log(a.favoriteBook.get);

It prints "b:1". So, unlike primitive PersistedDerivedPropertys, I think the user will have to load hint the favoriteBook:

const a = await em.load(Author, "a:1", "favoriteBook");
console.log(a.favoriteBook.get); // <-- now `Book`

Which is interesting b/c favoriteBook will now essentially have two different loaded states:

  1. Is my last-derived-value loaded, i.e. is the value b:1 loaded (which needs to be loaded anytime you want to call .get)
  2. Is my recalc-load-hint loaded, i.e. is books loaded so I could re-calc the value (which only needs to be loaded when Joist has detected favoriteBook should be recalced)

So I think we'll probably need some sort of new PersistedAyncRelation that both a) hides the .get until it's loaded, b) is integrated into MarkLoaded similar to ManyToOneReference, c) the implementation is a blend of PersistedAsyncField and ManyToOneReference to balance the dual "value loaded" / "recalc loaded" state.

This all seems doable, but has grown outside of my current/expired timebox. :-) I published #416 with the wip and we can pick it up from there at some point.

@stephenh stephenh added enhancement New feature or request hack day seems doable in a hack day labels Sep 11, 2022
@stephenh
Copy link
Collaborator Author

This was fixed in #639 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hack day seems doable in a hack day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant