简体   繁体   English

Grails .save()未保存关联的域

[英]Grails .save() is not saving an associated Domain

I have a domain Guest which has a belongsTo association with Person and User domains as follows : 我有一个域来宾 ,它与PersonUser域具有belongsTo关联,如下所示:

class Guest {

    static belongsTo = [
            person:Person,
            user : User // owner for guest
    ]


}

In my service GuestService.groovy , i am trying to update associated Person info associated with a given guest : 在我的服务GuestService.groovy中 ,我试图更新与给定来宾关联的关联个人信息:

@Transactional
    def updateGuests(def guestArray) {

        guestArray.each { data ->

            User user = User.findById(data["userId"])
            Guest guest = Guest.findByIdAndUser(data["guestId"] , user)
            if( ! guest )
                throw new NotFoundException("Invalid input parameters")

            println(" email : " + guest.person.email + " new email " + data["email"])

            Person person = guest.person
            //person = Person.findById(person.id)

            person.email = data["email"]
            person.phoneNumber = data["phoneNumber"]

            person.save(flush:true)
            //guest.save(flush: true)
        }
    }

I am unable to update Person info and i don't receive any errors too. 我无法更新人员信息,我也没有收到任何错误。 I Debugged the code and all the values are present till exit of the debug point .I searched on internet and other related questions on this stack but no question is related to this kind of problem . 我调试了代码,并且所有值都存在,直到调试点退出为止。我在Internet和此堆栈上的其他相关问题上进行了搜索,但没有与此问题相关的问题。

Have you tried person.save(flush: true, failOnError: true) ? 您是否尝试过person.save(flush: true, failOnError: true)吗?

It should overwrite a default behavior of returning null on save error and return exception instead. 它应该覆盖默认行为,即在保存错误时返回null并返回异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM