Retrieving a list of GORM persistent properties for a domain

前端 未结 3 1730
鱼传尺愫
鱼传尺愫 2020-12-08 00:47

What\'s the best/easiest way to get a list of the persistent properties associated with a given GORM domain object? I can get the list of all properties, but this list cont

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 01:30

    Now (strarting Grails 2.x) you don't even have to instantiate new DefaultGrailsDomainClass(...) and avoid unnecessary code executions. All domain class objects have injected property domainClass:

    def domainObject = new YourDomain()
    domainObject.domainClass.persistentProperties
    

    Or, if you haven't domain class object, you can get DefaultGrailsDomainClass from application context by domain class name - each domain class has a DefaultGrailsDomainClass registered as a Spring bean. So you can use, for example, Holders (assuming your domain class name is 'Foo'):

    def defaultGrailsDomainClass = Holders.applicationContext.getBean("FooDomainClass")
    defaultGrailsDomainClass.persistentProperties
    

提交回复
热议问题