How to Query with refresh including relations

8 views
Skip to first unread message

Esteban Maringolo

unread,
Nov 8, 2020, 7:27:23 PM11/8/20
to GLORP Mailing List
Hi,

I have a simple object Tournament that has a ToMany relation with TournamentCategory, I want to be able to force the refresh of the Tournament and also the TournamentCategories.

If I do `alsoFetch: [:e | e categories]` it brings a _single_ category in the categories selection.

And it is not that I want to refresh each category, I want to refresh the whole list, since it might have changed since it was read (new/removed elements).

Is it possible? How do you do that?

Regards!

Esteban A. Maringolo

jtuchel

unread,
Nov 10, 2020, 1:25:50 PM11/10/20
to glorp-group
I guess you'd have to refresh all categires individually. like

self session refresh: tournament.
tournament categories do: [:c| self session refresh: c].

I am not aware of a "mass refresh" that could bundle these statements into one select, so each category will be read individually (meaning 7 select statements for one tournament and 6 categories). But looking at #refresh: I could imagine this is not too hard to implement, as long as the new refreshAll: is only used for collections of objects of the same Class. And with a few hours more you could probably group the ids by descriptors and bundle the selects...


Joachim

Esteban Maringolo

unread,
Nov 10, 2020, 9:23:28 PM11/10/20
to GLORP Mailing List
On Tue, Nov 10, 2020 at 3:25 PM jtuchel <jtu...@objektfabrik.de> wrote:
>
> I guess you'd have to refresh all categires individually. like
>
> self session refresh: tournament.
> tournament categories do: [:c| self session refresh: c].

That I could do of course, but the point is that the categories
collection might have changed, not just each category.

Since some stuff is loaded in another system and then synchronized via
an API, it might be the case that in my Glorp session I have five
categories, but then a new update/sync came in and now there are only
three, completely different from the other ones. So the right thing
would be to re-read the whole collection of the ToMany mapping.

> I am not aware of a "mass refresh" that could bundle these statements into one select, so each category will be read individually (meaning 7 select statements for one tournament and 6 categories). But looking at #refresh: I could imagine this is not too hard to implement, as long as the new refreshAll: is only used for collections of objects of the same Class. And with a few hours more you could probably group the ids by descriptors and bundle the selects...

I think that removing the objects in the collection (each category)
from the registered objects and forcing the re query/instantiation of
the collection defined by that mapping would work.
With a proxied collection this would be simpler because by freeing the
value of the proxy and setting it as not instantiated it would cause
it to automatically instantiate it again.
One of my first experiments when doing my own ORM was to have all
object references intermediated by proxies for this very reason.

At this point this is beer talk, but if there were another Camp
Smalltalk there are a lot of improvements that could come out of these
talks. :-)

Regards,

Esteban A. Maringolo

Alan Knight

unread,
Nov 11, 2020, 8:59:16 PM11/11/20
to glorp...@googlegroups.com
My memories are getting pretty dusty at this point, but I think that what you're doing with the alsoFetch ought to work. The other option is you can send uninstantiate to the collection proxy, which would force it to re-query when accessed.

--
You received this message because you are subscribed to the Google Groups "glorp-group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glorp-group...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAJMgPCJPRAXc3FV6F%3DOPTQ97Q6U0B2FogRByoJRWFw27tK9HMw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages