deals with issues related to the definitions of domain model
Questions tagged [grails-domain-class]
689 questions
53
votes
1 answer
Grails domain class: unique constraint for multiple columns
Suppose a simple Grails domain class:
class Account {
String countryId;
String userName;
String password;
static constraints = {
...???...
}
}
It is required that user names are unique for a particular countryId, thus…

rainer198
- 3,195
- 2
- 27
- 42
29
votes
4 answers
Grails get child domain objects
I have two domain classes one is parent and other one is child and i have a hasMany relationship between them. Parent class has many childs and child class belongs to parent class.
And here is coding example.
class Parent{
String name
static…

786543214
- 855
- 4
- 14
- 29
18
votes
1 answer
Grails: find domain class by name
I want to allow users to traverse the domain classes and print out dumps of stuff. My frist problem: assuming the following works just fine:
//this works
class EasyStuffController{
def quickStuff = {
def findAThing =…

Mikey
- 4,692
- 10
- 45
- 73
16
votes
2 answers
Grails default sort of "hasMany" domain attributes
I'm trying to set default sort of my hasMany attribute using mapping statement. I'm following the grails doc but it doesn't work for me (grails 1.3.5). My code looks like:
class Note {
Calendar sendDate
static belongsTo = Message
}
class…

Mateo
- 193
- 1
- 2
- 5
15
votes
3 answers
How do I create a transient variable in a Grails Domain Class?
How do I set up a variable within a domain class that is not persistent. I want to be able to write and read to that variable, but I don't want it to be a part of the table.
The way to do this in rails is by setting up a variable with attr_accessor.…

coderberry
- 3,040
- 3
- 26
- 28
14
votes
3 answers
Method on class [] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails Correctly
PROBLEM
I know there is already a question in regards to this but I think that the issue that causes might be different based on what they are saying. I have the following setup:
grails version: 2.3.4
Hibernate plugin: runtime…

Viriato
- 2,981
- 7
- 40
- 54
14
votes
2 answers
running grails 2.1.3 tests in Intellij Idea: Bizarre error in Spock test: Cannot add Domain class [class x.y.Z]. It is not a Domain
I am in the process of upgrading to grails 2.1.x, and need to redo some of my old-style tests.
I just added a new test to my spock Spec, and for this test I need to mock an additional Domain class.
Before this, I had:
@Mock([Event, EventType])
Now…

Luis Muñiz
- 4,649
- 1
- 27
- 43
13
votes
4 answers
dateCreated, lastUpdated fields in Grails 2.0
I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic dateCreated and lastUpdated fields to manage the timestamps associated with creation and modification of the…

srkiNZ84
- 3,558
- 5
- 30
- 37
13
votes
3 answers
How to implement a "remote" Domain?
Imagine two Grails applications which share a domain class. Maybe a Book domain class.
One application is identified as the owner of the data, one will have to access the domain data. Something like amazon and the amazon web services.
I guess it is…

rdmueller
- 10,742
- 10
- 69
- 126
12
votes
2 answers
Grails transient properties not picked up on object creation
After migrating from Grails 1.3.7 to 2.0.4 I have noticed a problem with one of my domain classes where I use transient properties in order to handle passwords.
My domain class looks like this (simplified):
package test
class User {
String…

John Doppelmann
- 544
- 4
- 15
12
votes
3 answers
Update "lastUpdated" Field in Parent Domain Class in Grails
I have a parent domain class the has a hasMany of another domain class. Both the parent and the child domain classes have the lastUpdated and the dateCreated fields. My issue is that when I update a child domain class, I need the parent domain class…

anthonylawson
- 761
- 9
- 24
10
votes
2 answers
Grails: How to query objects in many to many mapping?
Hello I have the follwing domain classes.
class Student {
int age
static hasMany = [courses:Course]
}
class Course {
String name
static hasMany = [students:Student]
}
I want to find the Students taking Course (with id 1), with age…

enesness
- 3,123
- 5
- 31
- 33
10
votes
3 answers
How do I test if an Instance is persisted in the Database with GORM?
When I save an instance as:
test.save()
the save could fail. I could do
if (!test.save(flush:true) {
// save failed
}
Consider that case that I got an instance from another function and could not do this check because I will not save the…

Michael
- 32,527
- 49
- 210
- 370
9
votes
1 answer
Grails min constraint for date validation
I am a newbie in grails and groovy. I have a Project domain-class with start and end date. I want to put in a constraint specifying that the end date needs to be greater than the start date(and then further another child object of project needs to…

Ravindra Sane
- 472
- 3
- 10
8
votes
2 answers
Where should I place a transient domain class in a grails app?
Where should I place a transient domain class in a grails app?
Ie I have an Action class that will be passed about, and used, but never saved. Should this be in the grails-app/domain folder, or somewhere else?

C. Ross
- 31,137
- 42
- 147
- 238