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

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?
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?

Categories

HOME
tinymce
office365api
relay
grep
react-router
mean-stack
spagobi
cvs
jira
malloc
dxl
echarts
cloudkit
iggrid
php-7.1
apache-cayenne
leiningen
clearcase-ucm
opentracing
fatal-error
connection-string
excel-vba-mac
crystal-reports-2008
lucene.net
textfield
ml
orleans
hammerspoon
microsoft-sync-framework
chromebook
wpfdatagrid
phpfox
nhapi
filezilla
replaceall
google-cloud-nl
skia
bcd
functor
google-qpx-express-api
calibre
io-redirection
swisscomdev
angularjs-factory
outlook-api
total-commander
netcdf4
babel-core
taffy
chain-builder
sage-one
git-diff
elgg
crypt
font-size
nsarray
r-forge
capacity
mako
arrow-keys
sonarlint-vs
minimization
parallel-data-warehouse
xml-attribute
persist
essence
cartesian-product
google-places
endeca-workbench
qdialog
mutation-observers
purge
varargs
splash
nsight
key-management
sonarqube5.1.2
tt-news
google-style-guide
mdt
client-side-templating
device-manager
preferences
jboss-weld
concurrent-collections
stxxl
industrial
c18
tidy
listings
sqlperformance
type-equivalence
tinn-r
jquery-knob
mt
newtonscript
ticoredatasync
online-compilation
postgresql-performance
hgsubversion
work-stealing
xmlspy
xmemcached
meego
w3wp
lzh

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