加载开发数据的BootStrap.groovy存在问题。之前它总是加载数据,但现在已经停止在运行grails run-app时抛出以下错误。
Message: Validation Error(s) occurred during save():
- Field error in object 'spotlight.content.Profile' on field 'portfolio': rejected value [null];
我的2个模型如下;
class Portfolio {
Profile profile
String portfolioName
String portdescrip
Integer portpublished
Date dateCreated
Date lastUpdated
和
class Profile {
static belongsTo = [portfolio: Portfolio]
String portfoliohtml
String portfolioEmail
String portfoliocc
String portfolioAdmin
String portfolioFilestore
String portfolioColor
String bugzillaproduct
String bugzillacomponent
String rtqueue
String teamqueueemail
String etherpadurl
Integer siteupload
Date dateCreated
Date lastUpdated
在BootStrap.groovy文件中,我有以下内容;
import java.util.Date;
import spotlight.content.Profile
import spotlight.content.Portfolio
class BootStrap {
def init = { servletContext ->
def profile = new Profile(portfoliohtml:"No",
portfolioEmail: "ian@ian.com",
portfolioAdmin:"Ian Neilsen",
bugzillaproduct:"bz prod name",
bugzillacomponent:"comp name",
siteupload:1,
portfoliocc: "ian@ian.com",
portfolioColor:"red",
portfolioFilestore:"blah",
rtqueue:"queue name",
teamqueueemail:"ian@ian.com",
etherpadurl:"http://url.com",
).save(failOnError: true)
def portfolio = new Portfolio(portfolioName:"Portfolio 1",
portdescrip:"portfolio descrition field",
portpublished:1,
portfolio:profile).save(failOnError: true)
}
我已经尝试过将我的个人资料对象添加到投资组合对象的每一个化身都没有任何运气。正如我之前所说,这有效,现在已经停止抛出零错误。
让我难过任何想法?
欢呼声
答案 0 :(得分:2)
看起来你有几个错误。
一个(但不是导致错误消息)是,您尝试将profile
实例添加到portfolio
实例的portfolia
属性。 Portfolio
没有属性portfolio
。
关于您的错误消息,请尝试以下操作:
def portfolio = new Portfolio(portfolioName:"Portfolio 1", ...)
portfolio.profile = new Profile(...)
portfolio.save(failOnError: true)
如需进一步阅读,请查看grails docs的Many-to-one and one-to-one (GORM)部分。