Search code examples
grailsgrails-orm

Check property is present by property name


I want to check is a string contains the name of a valid property of one of my entity class.

I've figured several keys but at the end i've been unable to make them work and even not sure what it the best practice to do this.

Thanks in advance


Solution

  • Finally i decided to go with

    MyClass.metaClass.properties.find { it.name == params.searchedColName }
    

    I think is little better solution than @Andrew von Dollen proposal since i avoid playing with the spring context ... feel that is more groovier this way.