I have the following piece of code in ItemController.groovy
def list = {
params.max = 60
def storeYYId = params.id
[itemInstanceList: Item.list(params), itemInstanceTotal: Item.count()]
}
I have the following in Item.groovy:
class Item {
String itemName
static belongsTo = [store:Store]
static constraints = {
itemName(blank:false)
storeId()
}
}
This gives me an error since it tells me that there is no storeId property, but there is, since store_id is a foreign key to the Store table in the corresponding database.
Question1. How do I tell grails to let me access the properties of domains that are autogenerated by GORM, like the id and storeId in this case?
Question2. What code should I write in my ItemController.groovy in my list action, in order to retrieve only a list of items where the storeId == storeYYId ?
You should be able to access autogenerated properties in exactly the same way as you access properties that you define. The reason you’re getting an error is because Grails does not automatically generate a
storeIdproperty for theItemclass, the only properties it will autogenerate areversionandid(for bothItemandStore).You’ll need to write either a HQL or criteria query to retrieve these items. The criteria query would look something like this (untested)