0

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)

}

我已经尝试了将我的个人资料对象添加到投资组合对象的所有化身,但没有任何运气。正如我之前所说,这有效,现在已经停止抛出空错误。

让我有什么想法吗?

干杯

4

1 回答 1

2

看起来你有几个错误。一个(但不会导致错误消息)是,您尝试将profile实例添加到实例的portfolio属性中portfoliaPortfolio没有财产portfolio

关于您的错误消息,请尝试以下操作:

def portfolio = new Portfolio(portfolioName:"Portfolio 1", ...)
portfolio.profile = new Profile(...)
portfolio.save(failOnError: true)

如需进一步阅读,请查看grails 文档的多对一和一对一 (GORM)部分。

于 2012-10-24T06:40:11.140 回答