开发者

grails won't save but have no error

开发者 https://www.devze.com 2023-01-27 07:38 出处:网络
Hi I have a domain that so simple like the following // page 52 Bankruptcy Questions class FamilyLawFinancial{

Hi I have a domain that so simple like the following

// page 52 Bankruptcy Questions 
class FamilyLawFinancial{

    Date dateOfTheOrder ;
    boolean isPartyToFamilyLawProperty = false; 
    boolean isCurrentlyInvolvedInFamilyLawProperty = false;
    boolean isBecomeInvo开发者_运维问答lvedInProceedings = false;

    static belongsTo=[person:Person];

    static constraints = {
        dateOfTheOrder(nullable:true);
        isPartyToFamilyLawProperty(nullable:false);
        isCurrentlyInvolvedInFamilyLawProperty(nullable:false);
        isBecomeInvolvedInProceedings(nullable:false);
    }

    String toString(){
        "${id}"
    }
}

and here is the controller that save the data:

    def save = {
    def person = Person.get(session.curperson.id);
    def obj = FamilyLawFinancial.findByPerson(person);
    if(obj == null){
        obj = new FamilyLawFinancial();
        obj.person = person ; 
    }
    params.dateOfTheOrder = myutil.formatDate(params.dateOfTheOrder);
    obj.properties = params;

    println(obj.hasErrors());
    println(obj.dateOfTheOrder);
    if(obj.hasErrors() && !obj.save(flush:true)){
        println("errors: ${obj.errors}");
        flash.message = "error found";
        println("save familyLawFinancial errors: ${errors}");
    }else{
        flash.message = "saved ";
    }
    redirect(controller:'frontPage', action:'index'); return ;
}

The obj.hasErrors() produce false (it means no error) but it wont save into the database. Any idea how to debug this ?

ps: myutil.formatDate() --> for converting the Date String such as 19/11/2010 to Date()


if(obj.hasErrors() && !obj.save(flush:true)){

The condition after && will not be evaluated if the condition before evaluates to false.

As false && true evaluates to false, evaluating the second condition would be inefficient from the language's point of view.

After all, in this case, obj.save(..) never gets called.

0

精彩评论

暂无评论...
验证码 换一张
取 消