gorm


Is there a belongsTo mixed syntax for GORM many-to-many and back-reference


I've come across a peculiarity in GORM mapping.
What I expect table-wise is
models
designs (model_id -> models.id)
categories
categories_design (category_id, design_id)
To get a model_id in designs, I would use map syntax
static belongsTo = [model:Model]
So now, I also have a hasMany relationship between Design and Category and the owning side is Design.
The GORM manual says to denote an owning side using non-map syntax
static belongsTo = Category
BUT, I also need the back reference from Design to Model that uses map notation.
My question is how do you mix the 2 cases?
I have tried, in Design:
static belongsTo = [model:Model, category:Category]
This gets a runtime error - No owner defined between domain classes Category and Design in many-to-many relationship.
static belongsTo = [model:Model, Category]
This gives a compile error.
static belongsTo = [Model, Category]
The expected model_id is not created in Design, instead a whole new table for models_designs is created which is not right. But everything compiles and runs.
If you have a hasMany relation between Design and Category and Design is the owning side, should you not have a
static hasMany = [category: Category] in Design class
and
static belongsTo = Design in Category class.
In this way, you can still keep
static belongsTo = [model:Model]
in the Design class.

Related Links

Adding condition to findAll and findAllBy methods
Neo4j and Mongodb as datasource in Grails
GORM (varchar .save(), non DATE): ORA-01861: literal does not match format string
GORM addTo methods not found in Spock test
spring-boot property exception while externalizing datasource properties and using actuator
Mapping hasMany relation and saving the related data
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
What happens when two app servers in cluster start LiquiBase update (via Grails)?
use of mappedBy in Many to Many relationship in Grails
Domain class auto validation in grails
Grails Detached Criteria Query and “group by” and “having” clause
Script for saving large no of entries in mongodb
Does the multiple datasource feature of Grails 2.0 support relations?
How to avoid ImprovedNamingStrategy in joinTable in Grails
Grails 2 Show transient property that is an alias for id column
How to save GORM class with composite id made from its own field?

Categories

HOME
twitter
arduino-uno
gitlab
openmp
zeromq
magnific-popup
include
hashmap
spagobi
rsyslog
framework7
kalman-filter
leon
baqend
ravendb
mvvmcross
opengl-es-2.0
flyway4
portia
add
dacpac
apache-cayenne
dtrace
vaadin7
lombok
reactcsstransitiongroup
http-status-code-504
introduction
kryo
arabic
language-agnostic
jndi
qhull
cas
dynamic-featured-image
filezilla
atlassian-crucible
gitignore
skia
ioio
code-contracts
calibre
commit
uiswipegesturerecognizer
language-concepts
simplexml
android-browser
occlusion
code-search-engine
uft-api
tasker
hp-ux
avro4s
g-code
dynamic-reports
elmah
google-closure
nomethoderror
taffy
xml-documentation
dds
boost-multi-index
pebble-watch
idisposable
knockout-components
namecoin
pillow
mako
flow-control
mcafee
color-profile
color-picker
libpng
measures
qgraphicsview
make-install
independentsoft
maven-tomcat-plugin
wso2cloud
reactive-banana
content-length
ideamart
apache-commons-fileupload
createprocessasuser
unity3d-gui
system32
xc16
google-style-guide
javafx-webengine
openexr
sgen
mysql-error-1062
message-driven-bean
cloud-connect
algebraic-data-types
dir
sitemesh
excel-2003
ora-00911
gwt-rpc
back-stack
orchardcms-1.7
android-hardware
newtonscript
custom-backend
netdna-api
rfc1123
yetanotherforum
netbeans-7.1
sproutcore-2
filtered-index
brewmp
iweb
mdac
document-conversion

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App