Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.3.7
-
Fix Version/s: None
-
Component/s: Persistence
-
Environment:Windows
Description
Extending sample from documentation:
class Book {
static belongsTo = Author
static hasMany = [authors:Author]
String title
}
class Author {
static hasMany = [books:Book]
String name
}
we can add constraints e.g.
class Book {
static belongsTo = Author
static hasMany = [authors:Author]
String title
static constraints = {
title blank:false
}
}
class Author {
static hasMany = [books:Book]
String name
}
Now it should not be possible to save an author with a book without title:
new Author(name:"Stephen King") .addToBooks(new Book(title:'')) .save()
as new Book() violates title not blank constraint. But grails does not complain about it. Actually looking at the GrailsDomainClassValidator class we can see that method cascadeToAssociativeProperty does not take care of handling many-to-many relationships at all.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I have tried to run this with Grails 1.4.0.M1 and the result is event more alarming. Same sample now saves the Author but omits the Book. In the end we have a instance of an Author with a Book in the list of books but the Book is not stored in the database and there is no exception or error raised.
The example is located at https://github.com/halfdozenshots/GrailsBlogSamples