gorm


Grails 2 Show transient property that is an alias for id column


I just started out with Grails and I have a old MSSQL DB that needs a new fancy Grails UI on top of it. So far i have this code
class Foo {
version false
columns {
id column: 'legacy_id'
bar column: 'legacy_column_1'
baz column: 'legacy_column_2'
}
static transients = ['oldId']
public int getOldId() { id }
int id
int bar
String baz
}
and some extra scaffolding and so on. Everything works fins except one thing and that is that I can't get Grails to show me a column in the view with the name "Old Id" or for that matter show the column id. Whatever I tweak I always only end up with the columns bar and baz in the list view.
The internet is rather quiet on the topic so either I'm missing something obvious here and this is really simple or I have to hone my google skills...
You need to put some of the things into a mapping block
class Foo {
static mapping = {
version false
table 'old_foo' // whatever you legacy table name is
id column: 'legacy_id'
bar column: 'legacy_column_1'
baz column: 'legacy_column_2'
}
static transients = ['oldId']
public int getOldId() { id }
int id //not really needed
int bar
String baz
}
When you create the scaffolding with generate views or generate all it won't automatically add the id or oldId to the views - but you can add it yourself to ensure it's there using
${fooInstance.id}
${fooInstance.oldId}
You also don't need to have the int id specifically set - GORM creates it automatically.
One last thing - make sure in your DataSource.groovy file that you don't alter the database with the dbCreate line - I usually comment it out entirely when using legacy databases.

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
openlayers
keycloak
isabelle
mockito
tinymce
appx
include
raspberry-pi
react-router
webstorm
read-eval-print-loop
gis
yahoo-oauth
analysis
packages
binary-tree
fancybox
cross-validation
gorm
google-apps-marketplace
fallback
quickfix
ups
finite-automata
google-cloud-speech
amazonsellercentral
excel-2007
tibco-mdm
hammerspoon
emgucv
sparse-matrix
info.plist
fifo
bluestacks
uiswipegesturerecognizer
mapbox-gl
mmenu
picasso
overlap
main
leading-zero
temporary-files
ensembles
hp-ux
sql-server-agent
no-www
websphere-mq-fte
wptoolkit
scrollable
youcompleteme
chain-builder
pubmed
jquery-validate
promela
windows-iot-core-10
epson
messenger
visual-c++-2008
intrusion-detection
asp.net-4.5
moveit
make-install
hexdump
livequery
two-factor-authentication
wapiti
photobucket
vhd
collapse
metaclass
ruby-2.2
citrus-pay
rgeo
riak-cs
0xdbe
deis
mono-embedding
apache-commons-fileupload
iiviewdeckcontroller
census
pretty-print
operator-precedence
network-interface
bitcoinj
htmlcleaner
seaside
undefined-reference
html5-notifications
ivyde
ruby-datamapper
gridcontrol
dmoz
mt
ocx
getmessage
bubble-chart
removeclass
code-cleanup
heartbeat
subviews
asp.net-profiles
memory-size
avatar
aquaticprime
mediarss
zune
genealogy
ugc

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile