Is it possible to write your own validator in grails that will return a valid object?
Something like:
static constraints = {
name(validator: {val, obj ->
if (Drink.findByName(val)) return [Drink.findByName(val)]
})
}
In other words - if the Drink already exists in the DB, just return the existing one when someone does...
I have the project as set-up below. I am trying to delete a project, and I get the following:
2010-09-29 11:45:22,902 [http-8080-1] ERROR errors.GrailsExceptionResolver - deleted object would be re-saved by cascade (remove deleted object from associatio
ns): [Project#204]
org.hibernate.ObjectDeletedException: deleted object would be re...
Hi, I have two domain classes:
class A {
String Name
...
}
class B {
A request
B response
...
}
How can I get a list of unique As that are present as "requests" in B ? I tried
def g = A.findAll("from A as e, B as r where e=r.request")
But I have problems extracting the resulting objects.
Thanks
...
Is there a way of telling GORM not to persist a property? I'm planning to define a confirm password property on my User class that I'll use for validation, but shouldn't be persisted.
Thanks.
...
Hi,
I've got an issue with Grails where I have a test app with:
class Artist {
static constraints = {
name()
}
static hasMany = [albums:Album]
String name
}
class Album {
static constraints = {
name()
}
static hasMany = [ tracks : Track ]
static belongsTo = [artist: Artist]
String name
}
class Track {
static constraints...
I have the following Domains
class Committee {
String name
BoardCommitteeType boardCommitteeType
Date dateCreated
Date lastUpdated
User createdBy
User modifiedBy
static belongsTo = [
board: Board,
]
static hasMany = [
members: User
]
}
class User {
static hasMany = [ ...
I am using Nimble and Shiro for my security frameworks and I've just come accross a GORM bug. Indeed :
User.createCriteria().list {
maxResults 10
}
returns 10 users whereas User.list(max: 10) returns 9 users !
After further investigations, I found out that createCriteria returns twice the same user (admin) because admin has 2...
I am porting a Grails application from Oracle to MySQL database. The original Oracle version is a legacy database which uses a few complex Views leveraging Oracle's INSTEAD OF INSERT OR UPDATE feature which MySQL doesn't have. As a workaround I have implement Insert and Update methods on the Domain classes which point to these kinds of V...
I have a grails project with a class that I can delete no problem when doing it "manually" from the controller. I use the following code.
def delete = {
def projectInstance = Project.get( params.id )
def employee = projectInstance.employee
def projectarray = new ArrayList<Project>();
projectarray += employee.getProjects(...
I use the following Grails code to render a collection of SomeClass-objects as XML:
def someObjects = SomeClass.findAllByFoo(foo)
if (someObjects) {
render(contentType:"text/xml", text:someObjects as XML)
}
This works as expected most of the time. However, sometimes and depending on the content of someObjects the code fails with the...
Hello,
I'd like to use the Grails feature for creating/updating database tables on a limited basis. Specifically, I'd like Grails to manage some tables, but not all. Is there a way to limit the tables managed by Grails or is it an all or nothing proposition?
Thanks,
Steve
...
I am trying to figure out the most efficient / effective way of performing a certain type of query using Grails GORM.
This is the scenario where I want to query all of the children / linked items in a many to one relationship. This is a one way relationship whereby the many side used the id of the thing it is linked to.
One example in...
I have a domain object called User:
class User{
String username;
String firstName;
String lastName;
Zipcode zip;
}
I also have a Zip Code object:
class Zipcode {
String zip;
String city;
String state;
Float lat;
Float long;
}
The zipcode table should never be modified as it contains static reference data prepopula...
Hello,
I'm developing a small application on Grails 1.3.5 and I run into this very strange problem.
My domain classes feature some boolean typed fields. None of these fields is persisted when creating a new instance (and saving it of course).
For example, I have this domain class "Employee", defined as follows (simplified):
class Emp...
this has been bugging me,
lets say i have two model, category and product
class Category {
static hasMany = [products : Product]
String name
}
..
class Product {
String name
}
now, i want to delete product, which happens to exist in many category. i came up with these lines in my product beforeDelete methods
def beforeDelete =...
My problem is simple but I could not find any GORM syntax for this.
Consider the following class:
class Article {
String text
static hasMany = [tags: String]
static constraints= {
tags(unique: true) //NOT WORKING
}
}
I want to have one unique tag name per article defined in my constraints but I cannot make it with the ...
Hi all,
I've been trying to create a criteria builder containing a belongsTo relation and have yet to succeed. Consider the following model:
class Msg {
...
static belongsTo = [user: User]
...
}
class User {
...
Organisation organisation
...
}
I'm trying to make the following query:
Msg.createCriteria()....