我有三个表,场景,表单和一个链接表来连接两个,一个表单可以属于多个场景,一个场景可以有多个表单,链接表保存那个关系信息...怎么做我是用Grails做的吗?我不能改变存在的表的结构......:/
链接表的结构很简单:
form_id (matches PK of form table)
test_scenario_id (matches the PK on the test scenario table)
[order] (defines the order in which the forms should display)
在普通的旧SQL中,我可以使用如下的连接,但不知道如何将其转换为Groovy说话: -
select lnk_scenario_form.test_scenario_id, dbo.lnk_scenario_form.[order], dbo.form.form_id
from dbo.form
JOIN lnk_scenario_form on form.form_id = lnk_scenario_form.form_id
JOIN dbo.test_scenario on dbo.test_scenario.test_scenario_id = lnk_scenario_form.test_scenario_id
where lnk_scenario_form.test_scenario_id = SCENARIO ID
order by lnk_scenario_form.[order];
以下是我到目前为止设置的课程: -
class Form {
static constraints = {
formDesc(blank:false,maxSize:100)
}
static mapping = {
table "form"
version false
columns{
id column:"form_id"
formDesc column:"description"
}
}
String formDesc
}
和
package fartframework
class TestScenario {
static constraints = {
testscenariodesc(blank:false, maxSize:100, unique: true)
browser(inList:["RND","FF","CH","IE"], blank:false)
myrelease(blank:false, maxSize:10)
system(blank:false, maxSize:50)
subSystem(blank:false, maxSize:50)
}
static mapping = {
table "test_scenario"
version false
columns{
id column:"test_scenario_id"
testscenariodesc column:"description"
browser column:"browser"
myrelease column:"release"
system column:"system"
subSystem column:"subSystem"
}
}
String testscenariodesc
String browser
String myrelease
String system
String subSystem
String toString (){
"${testscenariodesc}"
}
}