Eager loading by default possible ?

7 views
Skip to first unread message

Jan van de Sandt

unread,
Jun 6, 2019, 12:31:48 PM6/6/19
to glorp-group
Hello list,

With a query you can use the alsoFetch:  method to "eager load" related objects. Is it possible to specify a mapping so that Glorp does this by default?

My Model is something like this:

Class A ----(*)--> Class B ----(1)--> Class C

Class A has a collection of B instances and each B instance refers to exactly one C instance. What I would like to have is that when Glorp loads the the collection of B instances for an A instance it also loads the C instances using a join query.

Cheers,
Jan.

Alan Knight

unread,
Jun 6, 2019, 1:02:34 PM6/6/19
to glorp...@googlegroups.com
Yes, it's definitely possible. Look for sends of alsoFetch: inside descriptors in the tests.

--
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 post to this group, send email to glorp...@googlegroups.com.
Visit this group at https://groups.google.com/group/glorp-group.
To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/212f6892-ae48-479b-b411-b149494208d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan van de Sandt

unread,
Jun 6, 2019, 2:37:08 PM6/6/19
to glorp-group
Yes, I found an example and now it works. 

The mappings looks like this:

mapping := (aDescriptor newMapping: ToManyMapping)
attributeName: #b;
referenceClass: B;
join: (Join
from: (table fieldNamed: 'ID')
to: (bTable fieldNamed: 'A_ID')).
mapping query alsoFetch: [ :each | each c ].

Thank you!


On Thursday, June 6, 2019 at 7:02:34 PM UTC+2, alan.knight wrote:
Yes, it's definitely possible. Look for sends of alsoFetch: inside descriptors in the tests.

On Thu, 6 Jun 2019 at 09:31, Jan van de Sandt <jvds...@gmail.com> wrote:
Hello list,

With a query you can use the alsoFetch:  method to "eager load" related objects. Is it possible to specify a mapping so that Glorp does this by default?

My Model is something like this:

Class A ----(*)--> Class B ----(1)--> Class C

Class A has a collection of B instances and each B instance refers to exactly one C instance. What I would like to have is that when Glorp loads the the collection of B instances for an A instance it also loads the C instances using a join query.

Cheers,
Jan.

--
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...@googlegroups.com.

jtuchel

unread,
Jun 13, 2019, 3:17:41 PM6/13/19
to glorp-group
Jan,


please be very sure you ALWAYS want these dependent objects loaded. We've used this just to find out there are situations in our Application where this is not desired.. ;-)


I have a related question I have been wondering about for a while:

What is the exact difference between shouldProxy: false and alsoFetch:?


All I've found out so far is that shouldProxy doesn't work as expected, but I haven't found out what exactly to expect ;-)))

Joachim

Jan van de Sandt

unread,
Jun 13, 2019, 3:53:57 PM6/13/19
to glorp...@googlegroups.com
Hi Joachim,

I also tried setting shouldProxy to false. But this results in 1 + N queries instead of a single query with a join. 

You are right that specifying alsoFetch in a mapping may result in loading too much data that you don't always need. Or the related data is already cached and the fetch is also not necessary. But in my concrete situation this is not the case.

Jan.



To unsubscribe from this group and stop receiving emails from it, send an email to glorp-group...@googlegroups.com.

To post to this group, send email to glorp...@googlegroups.com.
Visit this group at https://groups.google.com/group/glorp-group.
Reply all
Reply to author
Forward
0 new messages