register
other register

Wednesday, July 29, 2009

GORM Lazy

If we have the domain relations (one Order has many Items, and one Item can appear in many Orders) modelled below:

Order --* LineItem *-- Item

If we want the toString() method of the LineItem class to return its relation classes attributes, then that's where lazy strategy comes in handy.


class LineItem {

// relation
Order order
Item item

static mapping = {
columns {
order lazy: false
item lazy: false
}
}

String toString() {
return "Order no: $this.order.id, Item: $this.item.name"
}
}

No comments: