前景提要
HDC调试需求开发(15万预算),能者速来!>>>
if (category.save()) {
println 'new category saved!'
/*
def allgoods = [new gdepot2.Goods(title:'Grails',price:20.0,
description:'Grails Book...',photoUrl:''),
new gdepot2.Goods(title:'Groovy',price:20.0,
description:'Groovy Book...',photoUrl:'')
]
allgoods*.category = category
if(allgoods*.save()){
println 'all goods saved!'}
*/
def goods1 = new my.Goods(title:'Grails',price:20.0,
description:'Grails Book...',photoUrl:'')
goods1.category = category
if (goods1.save()) {
println 'goods1 saved!'
}
def goods2 = new my.Goods(title:'Groovy',price:20.0,
description:'Groovy Book...',photoUrl:'')
goods2.category = category
if (goods2.save()) {
println 'goods2 saved!'
}
}
在bootstrap中,让初始化的时候向表中插入数据,结果category表中可以插入数据,goods表中总是失败,这是为什么呢?
下面是表对应的domain
package my
class Goods {
String title
String description
BigDecimal price
String photoUrl
Category category
}
package my
class Category {
String categoryName
static hasMany = [goods:Goods]
static constraints = {
categoryName(unique:true)
}
}