2 * @author Graeme Rocher
5 * Created: Nov 22, 2007
7 package org
.codehaus
.groovy
.grails
.orm
.hibernate
8 class DeleteFromCollectionTests
extends AbstractGrailsHibernateTests
{
10 protected void onSetUp() {
17 static belongsTo = DeleteAuthor
24 static hasMany = [books:DeleteBook]
29 void testDeleteFromCollection() {
30 def bookClass
= ga
.getDomainClass("DeleteBook").clazz
31 def authorClass
= ga
.getDomainClass("DeleteAuthor").clazz
33 authorClass
.newInstance(name
:"Stephen King")
34 .addToBooks(title
:"The Stand")
35 .addToBooks(title
:"The Shining")
41 def author
= authorClass
.get(1)
44 assertEquals
2, author
.books
.size()
46 def book1
= author
.books
.find
{ it
.title
.endsWith("Stand") }
47 author
.removeFromBooks(book1
)
48 book1
.delete(flush
:true)
52 author
= authorClass
.get(1)
55 assertEquals
1, author
.books
.size()