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

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?
Grails - 2 domains and 1 form create/update/edit issues
Is there a belongsTo mixed syntax for GORM many-to-many and back-reference
Why do these Gradle tests throw exceptions?
In grails 2 when using multiple datasources, can I specify which datasource a criteria should use?
GORM methods are not accessible in Domain and Service classes
How to initialize the domain class properties with the values of another Domain class properties in grails
Grails Domain Embedded
How to get count of all items in a criteria GORM query

Categories

HOME
sendgrid
multithreading
gerrit
webpack
minimum-spanning-tree
reserved
nullpointerexception
youtube-dl
rsyslog
tizen-web-app
webpack-2
echarts
azure-media-services
node-notifier
metatrader4
spring-kafka
collectd
google-cloud-ml
remote-access
libtiff
graphlab
django-admin
solaris-10
reactive-cocoa
oxyplot
contextmenu
dbext
jasonette
microsoft-sync-framework
underflow
django-storage
poltergeist
selectedindexchanged
saas
facebook-apps
create-table
jspresso
fog
scaffold
gesture
mixture-model
serverside-rendering
twitch
angularjs-factory
lumberjack
websphere-mq-fte
qwt
google-datalayer
upstart
pango
sage-one
domain-model
mu
togetherjs
yii2-extension
nodebb
crypt
snmptrapd
iso8601
nxt
probability-density
pcf
thrust
nsfilemanager
simplewebrtc
pagedlist
ready-api
rhino-servicebus
ptrace
cloudbees
prerequisites
jms2
icu4j
comobject
retina
wyam
drawbitmap
php-ci
ami
bridge.net
formatjs
gadt
angularjs-ng-click
internet-connection
html-helper
mesa
android-radiobutton
heisenbug
rebol3
xceed-datagrid
rtmfp
floating-point-precision
ccss
web2py-modules
wsdl-2.0
unc
chuck
word-processor
venn-diagram
multipage
wse3.0
boost-filesystem
datareader
asp.net-mvc-areas
xsdobjectgen
nhibernate.search
forums
boost-smart-ptr
phonon
nerddinner
zend-decorators
private-members
wsdl.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App