I'm having some problems getting a many-to-many relationship working in grails. Is there anything obviously wrong with the following:
class Person {
static hasMany = [friends: Person]
static mappedBy = [friends: 'friends']
String name
List friends = []
String toString() {
return this.name
}
}
class Bo...
Hello,
I'm trying to do the below sql statement in GORM
select * from table1 where table1.x not in
(select x from table 2 where y='something');
so, I have two tables, and needs to find the entries from table 1 which are not in table 2. In Grails
def xx= table2.findByY('something')
def c = table1.createCriteria()
def ...
Hi, should always the "version" field be checked when updating a domain class object ? If so, is using a while with sleep an acceptable option ?
...
Hi, any quick tip to implement findAllByGreaterThan so I can filter those records which date field is today (from 00:00 up to present).
Thanks in advance
...
Is it possible to create a table that has no 'id'? For example, this is my domain:
class SnbrActVector {
int nid
String term
double weight
static mapping = {
version false
id generator: 'identity'
}
static constraints = {
}
}
When I run this SQL statement, it fails:
insert into snbr_act_...
Is there a way to fix the position of the columns in a domain? I have this domain:
class SnbrActVector {
int nid
String term
double weight
static mapping = {
version false
id(generator: 'assigned')
}
static constraints = {
nid(blank:false)
term(blank:false)
weight(blank:...
Here DealerID can be nullable and CarID, TyreID are unqiue.
The problem I have noticed is:
Grails ignores nulls in unique constraints.
...
Hi guys,
I have these two domains Car and Driver which have many-to-many relationship. This association is defined in table tblCarsDrivers which has, not surprisingly, primary keys of both the tables BUT additionally also has another boolean field deleted. Herein lies the problem. When I find/get query on domain Car, I am fetched all re...
Hey all,
I'm currently trying to create a Friendship domain object to link two User objects (with a bit of additional data: createDate, confirmedStatus). My domain model looks as follows
class Friendship {
User userOne
User userTwo
Boolean confirmed
Date createDate
Date lastModifiedDate
static belongsTo = [userOne:User , userTwo:User...
Hello,
I was trying the grails sample programs from http://github.com/grails/grails-samples.git . It is also part of the Definitive Guide To Grails book. The steps (as per grails-samples/dgg/README.txt).
Installed mySql --> created user (gtunes), db (gtunes_ch17) etc
set GRAILS_HOME, PATH to grails 1.1 ver
Grails upgrade
grails app-r...
Our main domain object has multiple string[] properties (various configuration options) and we are thinking of an elegant way to persist the data. GORM creates joined table for the each array so we end up with about dozen joined tables.
I wonder if it would be possible to serialize each array into single column of the main table (somew...
Is it possible to access the relationship table when doing HQL statement?
As an example, I have 3 tables: account, commitment, account_commitment. It was generated using these domains:
class Account {
static hasMany = [ commits : Commitment ]
String name
}
class Commitment {
static hasMany = [ actors : Account ]
String ...
Hi, I have 2 domain classes
class A {
....
static hasMany = [bs:B]
}
class B {
int code
....
}
How can I list the number of ocurrences of all codes in B in all the A table?
Something like
b.each { thisb ->
int ocurrences = A.bs.findAll{it == thisb}.size()
...
}
Thanks
...
I have a relationship like this:
class E {
string name
hasMany = [me:ME]
}
class M {
float price
}
class ME {
E e
M m
int quantity
}
And I'd hate to iterate to achieve this: "obtain the sum of the quantity in ME times the price of the corresponding M for a given E".
Any hints on how to implement it using GORM/HQL ?
Thanks...
I'm trying to determine how to find/retrieve/load objects efficiently in terms of a.) minimizing calls to database and b.) keeping the code as elegant/simple as possible (i.e. not writing hql etc.).
Assume you have two objects:
public class Foo {
Bar bar
String badge
}
public class Bar {
String name
}
Each Foo has a bar...
Using GORM embedded can we add data for both the classes at once? Can the scafolding be done for these ? grails Embedded
...
I tried following this reference and this is now my domain's code:
class SnbrActVector {
long nid
String term
double weight
static mapping = {
version false
nid index:'Nid_Idx'
}
static constraints = {
term(blank:false)
}
}
What I want is to do is to add an index key for 'nid' col...
Is there a "best practice" or defacto standard with how much of the GORM functionality one should test in the unit/functional tests?
My take is that one should probably do most of the domain testing as functional tests so that you get the full grails environment. But what do you test? Inserts, updates, deletes? Do you test constraints e...
How do I translate:
SELECT COUNT(*) AS `count`, `a` FROM `b` GROUP BY `a` ORDER BY `a`
into grails or gorm query?
...
I have a method which has domain name as a String parameter.
def modelName="Equity"
I want to use it like
def results=modelName.findAll()
Please guide me!
...