Interesting that this is not built into grails. As many people know who use grails you automatically get dynamic “findBy” methods on persisted objects. It is incredibly useful and provides easy access to attributes of a persisted class. The only problem is when you try to do the same thing on a “hasMany” relationship of that class. For example:
You can do:
1 | Airport.findByName("MSP") |
You cannot do:
1 | Airport.findByFlights(flight) |
What do you do? In my case, I decided to make it.
Here is my implementation: