Reputation: 137
I have the domain classes TestUnit
, TestParameter
and ParameterRange
as shown below.
class TestUnit {
static hasMany = [testParameters : TestParameter]
}
class TestParameter {
static hasMany = [paramRanges : ParameterRange ]
static belongsTo = [testUnit : TestUnit]
}
class ParameterRange {
static belongsTo = [testParam : TestParameter]
}
I want to add the TestUnit
object (i.e, testUnitInstance.id
) in the ParameterRangeController
.
Since i'm new to grails i don't know how to do that could anyone please explain it to me?
What I've tried:
def testUnitId = params.testUnitId
def testUnitInstance = TestUnit.get(testUnitId)
def testParameterInstance = TestParameter.get(params.id)
[parameterRangeInstanceList: testParameterInstance.paramRanges, parameterRangeInstance: new ParameterRange(),testParameterInstance:testParameterInstance, page:"Range", testUnitInstance:testUnitInstance]
Upvotes: 0
Views: 121
Reputation:
You can manipulate more than one domain class in a controller or service, there's no restriction to that.
class ParameterRangeController {
def show() {
//you can get other domain classes...
TestUnit theUnit = TestUnit.get(1)
render view: 'show', model: [theUnit:theUnit, ...]
}
}
Since TestUnit
is related to TestParameter
, you can also access it like:
ParameterRange range = ParameterRange.get(1)
println range.testParam.testUnit
I suggest you to take a look in the docs about GORM, there's a lot of useful info.
Upvotes: 2