Questions tagged [grails-domain-class]

deals with issues related to the definitions of domain model

676 questions
51
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…
28
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…
Chaman
  • 805
  • 4
  • 14
  • 27
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,332
  • 9
  • 40
  • 70
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
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,801
  • 5
  • 36
  • 51
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,065
  • 1
  • 23
  • 39
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,408
  • 3
  • 24
  • 32
13
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
  • 2,350
  • 3
  • 20
  • 25
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
  • 9,867
  • 9
  • 62
  • 117
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
  • 534
  • 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
  • 752
  • 9
  • 23
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…
javanes
  • 3,193
  • 5
  • 28
  • 33
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
9
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…
confile
  • 29,115
  • 44
  • 187
  • 340
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
  • 28,735
  • 39
  • 139
  • 230
1
2 3
45 46