GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / orm / hibernate / DeleteFromCollectionTests.groovy
blob357aab9ae04bc013025cfb52a7fa1db3e52b8a85
1 /**
2 * @author Graeme Rocher
3 * @since 1.0
4 *
5 * Created: Nov 22, 2007
6 */
7 package org.codehaus.groovy.grails.orm.hibernate
8 class DeleteFromCollectionTests extends AbstractGrailsHibernateTests {
10 protected void onSetUp() {
11 gcl.parseClass('''
12 class DeleteBook {
13 Long id
14 Long version
15 String title
16 DeleteAuthor author
17 static belongsTo = DeleteAuthor
19 class DeleteAuthor {
20 Long id
21 Long version
22 String name
23 Set books
24 static hasMany = [books:DeleteBook]
26 ''')
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")
36 .save(flush:true)
39 session.clear()
41 def author = authorClass.get(1)
43 assert author
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)
50 session.clear()
52 author = authorClass.get(1)
54 assert author
55 assertEquals 1, author.books.size()