Grails will not persist, but have no error

Hi, I have a domain that is as simple as

// page 52 Bankruptcy Questions 
class FamilyLawFinancial{

    Date dateOfTheOrder ;
    boolean isPartyToFamilyLawProperty = false; 
    boolean isCurrentlyInvolvedInFamilyLawProperty = false;
    boolean isBecomeInvolvedInProceedings = 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 saves 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 ;
}

obj.hasErrors () creates false (this means no error), but it will not be stored in the database. Any idea how to debug this?

ps: myutil.formatDate () -> to convert a date string such as 11/19/2010 to Date ()

+3
source share
1 answer
if(obj.hasErrors() && !obj.save(flush:true)){

The condition after &&will not be evaluated if the condition before the assessment is equal false.

Since it false && trueis evaluated as false, the evaluation of the second condition will be ineffective from a language point of view.

, obj.save(..) .

+6

Source: https://habr.com/ru/post/1777597/


All Articles