Override getter and setter in grails domain class for relation

前端 未结 1 1358
粉色の甜心
粉色の甜心 2021-01-12 19:31

How to override getter and setter for field being a relation one-to-many in grails domain class? I know how to override getters and setters for fields being an single Object

相关标签:
1条回答
  • 2021-01-12 19:54

    Need the reference Set<Title> titles.

    class Entity {
        Set<Title> titles
    
        static hasMany = [
            titles: Title
        ]
    
        public Set<Title> getTitles() {
            if(titles == null)
                return null;
            return titles.findAll { r -> r.isActive == true }
        }
    
        public void setTitles(Set<Title> s) {
            titles = s
        }
    }
    
    0 讨论(0)
提交回复
热议问题