Grails проблема с правильным каскадом, используя hasOne и ownTo вместе - PullRequest
0 голосов
/ 02 октября 2018

Я ошибаюсь, используя hasOne и ownTo вместе.

class AlphaPhase{
  //want to store the next phase (if there is one) as a column on this table
   static belongsTo=[nextPhase:BetaPhase]
   static constraints{
         nextPhase(nullable:false);
   }
}

class BetaPhase{
   //defer storing the id of the relationship to the child table
   static hasOne=[previousPhase:AlphaPhase]
}

BetaPhase beta=new BetaPhase();
beta.previousPhase=existingAlphaPhase;
beta.save();

Столбец AlphaPhase.nextPhase никогда не сохраняется с новым идентификатором BetaPhase.(Временная проблема, так как новая бета не сохраняется во время установки?) AlphaPhase остается сиротой со значением, установленным в NULL.

Могу ли я это исправить, не прибегая к чему-то вроде

   def beta=new BetaPhase();
   beta.save();
   existingAlphaPhase.nextPhase=beta;
   existingAlpha.save();
...