I have lots of domain classes in my project. Many of them has type column. For example: User table has userType column, Book table has bookType column. I often pass these types into GSP g:select source by calling BookType.list() method. But problem is if GSP contains lots of g:select then I have to execute lots of redundant query.
And another problem is when I create a new Domain instance, I have to get these constant types from DB by following way
Book book = new Book();
book.bookType = BookType.findByName(BookTypes.COMICS);
Here I also have the same problem, I have to execute redundant query. Is there any good design to do all these stuff without executing these redundant queries?
If the
typesare not very volitile, I assume that is the case because I can see you defined anenumfor type. Try usingenum, totally -- I mean, don't bother with the database table at all to back that up. For example,Then, in your domain, do something like,
Then, you can simply do something like this,