I'm using grails 2.4.4.
I have the domain
class Post {
Integer nbrOfFavorites
static hasMany = [
favorites : Favorite
]
static mappings = {
nbrOfFavorites formula: '(select count(1) from favorite f where (f.post_id = id))'
}
}
The problem is that nbrOfFavorites is being created in the database, so retrieving it doesn't take into account the formula.
Is there something wrong in my syntax ?
Thanks
Yes there is a typo in the syntax. Change mappings
to mapping
, like:
static mapping = {
nbrOfFavorites formula: '(select count(1) from favorite f where (f.post_id = id))'
}