0
votes

I am currently reading about eager vs lazy loading. I am confused and comparing it to load vs no-load.

let's say i have two sections of UI.In one of them i want to show child data along with parent data and in second UI i am just showing parent data.Then i should write two different calls at database level,one is loading child data and another in loading only parent data.

How lazy/eager loading can helpful in this case because if i do lazy loading then it will consume more time in first case as it will query later rather than using joins etc. and if i use eager then it will consume time in case 2 as there is no need of child data.

Please let me correct if i am wrong and tell me some cases where eager/lazy loading can be helpful.

1

1 Answers

2
votes

I will show this by an example. The scenario is as such;

You are a parent who has a kid with a lot of toys. But the current issue is whenever you call him (we assume you have a boy), he comes to you with all his toys as well. Now this is an issue since you do not want him carrying around his toys all the time.

So being the rationale parent, you go right ahead and define the toys of the child as LAZY. Now whenever you call him, he just comes to you without his toys.

But you are faced with another issue. When the time comes for a family trip, you want him to bring along his toys because the kid will be bored with the trip otherwise. But since you strictly enforced LAZY on the child’s toy, you are unable to ask him to bring along the toys. This is where EAGER fetching comes into play.