domain driven design - Grails - associations by referencing id only -
i'm trying employ domain driven design application, , in order limit deep traversal between aggregate roots, advice associate them using identities. have next domain classes,
person
class person { integer age string name } and phonebill
class phonebill { // reference person long accountholderid bigdecimal amount } as is, setup can work. however, want add together foreign key constraint accountholderid create sure value set exists in info store. official grails docs don't seem cover this.
assuming person object still has id, can add together custom validator returns error if id isn't valid.
class phonebill { // reference person long accountholderid bigdecimal amount static constraints = { accountholderid validator: { !person.exists(it) ?: 'your.custom.error.message.key' } } } note .exists() available grails 2.3.x, believe. if you're using older version, can phone call .get() well.
grails domain-driven-design
No comments:
Post a Comment