deals with issues related to the definitions of domain model
Questions tagged [grails-domain-class]
689 questions
5
votes
1 answer
Unable to use addTo with hasmany grails domain
I have 2 tables in grails with mysql
say A and B
The scenarios that I want to implement here are :
(1)instance of A can have zero / one / more than one instance of B.
(2)when instance A is deleted then all its related Bs must be deleted.
(3)each…

akash777.sharma
- 702
- 10
- 30
5
votes
2 answers
Grails Command Objects custom Validate Message Codes
When using command objects like:
class UserCommand {
String name
static constraints = {
name blank: false, unique: true, minSize: 3
}
}
you can use them to validate objects without making them persistent. In my case I would…

Michael
- 32,527
- 49
- 210
- 370
5
votes
1 answer
Deserialize a JSON object with support for embedded associations
Is there an easy way to deserialize a JSON string to a domain class with support of embedded association; belongsTo and hasMany
{
name: "Customer",
contact: {
name: "Contact"
}
}
class Customer {
name
Contact contact
}
class…

ken
- 3,745
- 6
- 34
- 49
5
votes
4 answers
What is a good workflow for database migration in Grails?
I want to use the database-migration grails plugin for database migration. When I start my Grails app the first time all the database tables are created automatically. The production setting in my DataSource.groovy is:
production {
dataSource…

Michael
- 32,527
- 49
- 210
- 370
5
votes
3 answers
How do I create and XOR validation for two fields in a Grails domain class?
I have an issue where my domain class has two potential mutually exclusive external keys, either a serial number or a legacy lookup value.
Since I'm not sure which one I'll have for any given entry, I've made them both nullable and added custom…

GeoGriffin
- 1,065
- 11
- 26
4
votes
1 answer
How to unit test grails domain class that has a relational mapping?
The output of my test gives com.example.book.Book : null. When I debug the test, b object is created with "MyBook" as its name. But since its has a static mapping belongsTo, the test fails. How do I make this work. When I comment the belongsTo…
user235273
4
votes
2 answers
Grails createCriteria group by (groupProperty function) multiple attributes
I'm wondering if grails createCriteria supports group by multiple attributes like pure sql does. I'd like to list entries like this:
def criteria = DomainClass.createCriteria()
def results = criteria.list {
groupProperty('parameterA')
…

kuceram
- 3,795
- 9
- 34
- 54
4
votes
1 answer
Need ideas in designing Domain classes Grails
I am learning Grails, I am trying to build a small application. And for now I am working on the registration part.
There are 3 different views for registration process
1) As an employee my registration view is different with different fields
2) As…

srisris
- 569
- 2
- 9
- 28
4
votes
1 answer
How does one mix 'Reference' and 'No Reference' belongTo relationships in one Domain Class?
In Grails belongsTo allows one domain class to establish a cascading relationship with another domain class. There are two styles of relationships when using belongsTo: Reference and No Reference. Reference creates a property on the owned object…

Mark Rogers
- 96,497
- 18
- 85
- 138
4
votes
2 answers
Grails Integration Test Does NOT Rollback
I'm learning grails from the book "Grails In Action" and I'm trying to run integration tests from the examples. In the book it says that each integration test function should roll back its operations as each test finishes. It is NOT rolling back…

jmq
- 10,110
- 16
- 58
- 71
4
votes
2 answers
Grails / Gorm : Difference between declaring object and describing relationship?
I'm having trouble understanding the difference between declaring a domain-object in another domain and specifying the relationship between the domains.
Sample code:
class User {
Book book
}
versus
class User {
static hasOne = Book
}
class Book…

Daniel
- 170
- 2
- 11
4
votes
1 answer
Custom Grails validation
I would like to check to make sure two fields are not equal and one is greater then the other. Say yearBorn and yearMarried. They cannot be equal and yearMarried must be greater then yearBorn.

Josh K
- 28,364
- 20
- 86
- 132
4
votes
2 answers
How to add validation to limit number of rows being created
I have a Grails domain class. I would like to add a validation such that when the application is running in TEST environment, the domain class can't have more than 100 records.
I can't figure out the best way to add this type of validation. I am on…

Anthony
- 33,838
- 42
- 169
- 278
4
votes
1 answer
Grails How to call service from static method of domain class?
I have a static method on my domain class, and want to get all the business logic out of the domain class definition into the service, but I can't call the service in the domain class static method since the service itself is defined on the instance…

GGizmos
- 3,443
- 4
- 27
- 72
4
votes
3 answers
How to exclude some fields when listing Grails domain?
I'm wondering how can I list Grails domain and exclude some fields at same time. I'm guessing solution must be simple but I just can not see it.
I prepared some example with domain User:
class User implements Serializable {
String username
…

matox
- 885
- 11
- 27