Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to eager load a collection in ebean?

What is the correct way to eager fetch a nested collection in ebean and Play Framework 2? I tried this:

Registration registration = find
    .fetch("participants")
    .fetch("participants.fieldValues")
    .fetch("participants.fieldValues.field")
    .where().eq("token", token).findUnique();

For some reason registration.participants.fieldValues.field objects only have an id. The rest of the field properties are null. E.g. field.name is null when it should have a value.

Edit: If I make Field.name private and add a getter/setter for it, then I can get its value. But since I'm using fetch("participants.fieldValues.field") shouldn't that make it eager fetch without needing the getter/setter?

like image 1000
TomahawkPhant Avatar asked Jan 20 '13 17:01

TomahawkPhant


1 Answers

Magic that does not work is a waste of time for everybody. I have had numerous issues with genrated getters and setters. Some also related to referencing models in templates. I created getters and setters and kept fields private for my ebean models and never looked back.

like image 106
col Avatar answered Oct 18 '22 03:10

col