Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails 'false' unique error
    primarykey
    data
    text
    <p>I have the following domain classes (shortened version)</p> <pre><code>class TalkingThread { static hasMany = [comments:Comment] Set comments = [] Long uniqueHash } </code></pre> <p>and</p> <pre><code>class Comment { static belongsTo = [talkingThread:TalkingThread] static hasOne = [author:CommentAuthor] Long uniqueHash static constraints = { uniqueHash(unique:true) } } </code></pre> <p>and</p> <pre><code>class CommentAuthor { static hasMany = [comments:Comment] Long hash String name String webpage } </code></pre> <p>the following methods</p> <pre><code>public TalkingThread removeAllComments(TalkingThread thread){ def commentsBuf = [] commentsBuf += thread.comments commentsBuf.each{ it.author.removeFromComments(it) thread.removeFromComments(it) it.delete() } if(!thread.save()){ thread.errors.allErrors.each{ println it } throw new RuntimeException("removeAllComments") } return post } public addComments(TalkingThread thread, def commentDetails){ commentDetails.each{ def comment = contructComment(it,thread) if(!comment.save()){ comment.errors.allErrors.each{ println it} throw new RuntimeException("addComments") } thread.addToComments(comment) } return thread } </code></pre> <p>Sometimes I need to remove all of the comments from a TalkingThread and add comments that share the same uniqueHashes. So I call the <em>removeAllComments(..)</em> method, and then the <em>addComments(..)</em> method. This causes a </p> <p><em>Comment.uniqueHash.unique.error.uniqueHash</em> which caused by a supposedly deleted comment and a 'fresh' comment being added. </p> <p>Should I be flushing? Maybe there is something wrong with my domain classes?</p> <p><strong>Edit</strong> Expansion of question.</p> <p>Maybe this is a different question, but I thought that the session has deleted all associations and objects. Therefore the session state is aware that all <code>TalkingThread</code> comments have been deleted. Of course this has not been reflected in the database. I also assumed that the 'saving' of new Comments would be valid given that such 'saving' is consistent with the session state. However such 'saving' would be inconsistent with the database state. Therefore, my understanding of how grails validates objects in relation to session and database state is flawed! Any help in understanding the process of validating saves with respect to session and database states would also be appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload