In Grails, is “property” a reserved word?

Tag: grails Author: ringkingme Date: 2009-09-13

In Grails, is "property" a reserved word? That is, can I name a domain class Property and have its owner reference it by properties? Example:

class Thing {
    static hasMany = [properties: Property]
}

class Property {
    static belongsTo = [thing: Thing]
}

When I try to add a Property to a Thing I get the error:

Exception thrown: No signature of method: org.codehaus.groovy.grails.web.binding.DataBindingLazyMetaPropertyMap.add() is applicable for argument types: (Property) values: [Property : null]

groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.grails.web.binding.DataBindingLazyMetaPropertyMap.add() is applicable for argument types: (Property) values: [Property : null]

    at ConsoleScript10.run(ConsoleScript10:3)

Is there a list of all Grails reserved words?

Best Answer

I'm not sure that Property is reserved, but properties is treated specially for domain classes since it's used for data binding. What happens when you change:

static hasMany = [properties: Property]

to something like

static hasMany = [myProperties: Property]

Other Answer1

While I cant find any file with the name Property in grails, it is wise not to use such a common word - who knows when it might become reserved in the future?

What would happen if you just prepended your classname with something, like BlahProperty?

Other Answer2

Grails is a web framework. In general, only languages really have reserved words. The reserved words of Groovy are all those reserved by Java, plus a few others. The complete list is shown here.

You'll notice that it does include "property", which was a big surprise to me, as I've no idea what it's used for, and I think/thought I know Groovy reasonably well. Perhaps it's reserved for future use?