Hi,
in my domain model, I have a method that does something with my data.
e.g.
class Person {
String lastname
String firstname
String bigname() {
return lastname.toUpperCase()
}
static namedQueries = {
withBigname { name ->
eq(this.bigname(), name)
}
}
}
I want to use t...
Hi,
I'm trying to write a simple integration test, but having some trouble with Domain Objects. I've read on unit testing but can't figure it out.
This is my simple test:
User user = User.get(1)
controller.params.userid = "1"
controller.session.user = user
controller.save();
The error message is:
groovy.lang.Mis...
Hi,
I need to add a JNDI datasource from a legacy database to my Grails (1.2.2) application.
So far, the resource is added to my Tomcat (5.5) and DataSource.groovy contains:
development {
dataSource {
jndiName = "jdbc/lrc_legacy_db"
}
}
I also created some domain objects mapping the different tables to comfortably load...
assuming the following example:
I have a User class and a Item class and a user can have many items
1) Is there a combined dynamic method to get all the items for a user and also sort them after a Property? I have a controller action that gets the items for a user and send them to the view, and the view will render them all with < g:e...
I would like to create a one-to-many association that does not cascade deletes. Reading the Grails Reference it says
The default cascading behaviour is to cascade saves and updates, but not deletes unless a belongsTo is also specified
That isn't the behavior I'm seeing. With the following class implementations I get cascaded updat...
I am using Grails and am quite surprised by the way hasMany relationships work. I have a typical hasMany relationship where the parent id is in the child table. When I insert a child and try to save it through the parent object, the parent object's version id gets incremented. My question is: Why should the parent's version id change whe...
I have a User class and a Item class and a user can have multiple items.
I want to select some users based on other property using finndAllByProperty and adding the pagination parameters (see http://www.grails.org/doc/1.2.2/ref/Domain%20Classes/findAllBy.html .)
The problem is that I want to sort the result based on how many items ea...
I have a couple of domain classes defined, Employee and EmployeeDesiredSkill,
Employee has
static hasMany = [employeeSkill:EmployeeDesiredSkill]
and EmployeeDesiredSkill has
static belongsTo = [employee:Employee]
Yet groovyc is giving me a bunch of errors like the following:
[groovyc] Compiling 15 source files to C:\dev\JavaTes...
I'm using Grails 1.2.4. I would like to know on how can I sort by "countDistinct" (descending) and with groupProperty inside a projections.
Here are my domains:
class Transaction {
static belongsTo = [ customer : Customer, product : Product ]
Date transactionDate = new Date()
static constraints = {
transactionDat...
Hello,
Lets say I have two domain classes:
class User {
String name
Role role
}
class Role {
String name
static belongsTo = [user: User]
}
and I create some records:
def r1 = new Role(name: "role1").save()
def r2 = new Role(name: "role2").save()
new User(name: "user1", role: r1).save()
new User(name: "user2", role: r2).save...
Hi,
Is there a way to write a custom validator that will perform different validations according to field values?
For example
class myModel{
A a;
B b;
String prop
static belongsTo:[m:myModel]
constraints{
prop(validator:{
val,obj->
if (obj.a== null){
unique:[b,prop]
...
This solution works but performance is lower than expected. A query returning 200K rows takes several minutes and pegs the CPU on my dev box. Running the same* query in query analyzer returns all results in < 1 minute.
Class MyController {
def index = {...}
...
def csv = {
...
def rs = DomainClass.createCritera().scroll {}
...
Hello all,
I am trying to set up a few domain classes. I will explain it in english, and I am wondering how the domain would be set up in grails. Capitalized words are my domains
An Employee has an Education. An Employee has many Employer (past and present). An Employee had one or many Project for each Employer. Project have a Role, Cl...
I can write:
def c = Transaction.createCriteria()
def transactions = c.list {
projections {
groupProperty("product")
countDistinct("id")
}
maxResults(pageBlock)
firstResult(pageIndex)
}
But can't write this:
def transactions = Transaction.createCriteria() .list {
projections {
groupPropert...
in Grails, Is there a way to limit the size of the column to which the enum is mapped. In the following example, i would like the column type to be char(2)
enum FooStatus {
BAR('br'), TAR('tr')
final static String id
}
class Foo {
FooStatus status
static constraints = {
status(inList:FooStatus.values()*.id,size...
I'm new to grails and receive the following error:
No signature of method: Something.findAll() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [from Something AS s WHERE s.some_number LIKE ?, [%asdf%]]"
The error occurs when I run test-app. It occurs in the following place:
SomethingVO[] findBySomeN...
As I noticed in the answers of another question there are a few problems when testing finder methods in GORM.
I want to get all objects from Something and have support for sorting and pagination, so I wrote this:
SomethingListVO findAllSomethings(int offset = 0, int limit = 50) {
def somethingCount = Something.count()
def some...
For the life of me I cannot seem to get relationships to work on mapped tables with Grails. I have two domains I am trying to join, Resources and Cassettes. A Resource can have many Cassettes.
If i run the code below using scaffolding I get an error "Unknown column 'this_.cassette_id' in 'field list'". If i try to define the cassette_i...
I have a Skill class, which hasMany RoleSkills.
I have a RoleSkills class which belongsTo Role and Skill
I have a Role class which hasMany RoleSkills
For Role, I have a mapping that cascades operations to RoleSkills. The question is, does it make sense for RoleSkills to "cascade" back to Skill?
I basically want to have a RoleSkill cr...
I have an object foo, foo has a collection bars and each bar has a collection of baz
class foo {
static hasMany = [
bars : Bar
]
}
class bar {
static belongsTo = [
foo : Foo
]
static hasMany = [
bazs : Baz
]
}
class baz {
static belongsTo = [
bar : Bar
]
}
I was trying to create and save the foo structure this wa...