I am new to Grails , I have some issue as stated below.
I have 2 domain classes : Parent and Child. I am storing arrays of arrays into database.
Parent class is :
class Parent{
static hasMany = [child: Child]
}
Child class is :
class Child {
String time
String record
String value
static belongsTo= [parent: Parent]
static constraints = {
time(blank: false)
record(blank: false)
belongsTo(blank: false)
}
}
Now my requirement is :
I need to retrieve the child's latest records that contain multiple rows in the database with unique parent id. e.g : Parent's latest id is 7. Child table contains nearly 10 records on parent id 7. I want to retrieve all these 10 records with the reference of the parent id(7).
Please some one help to write a code/query .
gorm
is a greate ORM
you could use following:
def parent = Parent.get(7)
def childList = Child.findAllByParent(parent);
read this, it'll help you to understand gorm
better.