|
Hi all,
I have a legacy database and I need to create a One-to-One association. class User { def name static hasOne = [data: Data] static mapping = { table 'UserTable' version false id column: 'myId' name column: 'theName' data column: 'myId' } } class Data { def email static belongsTo = [user: User] static mapping = { table 'DataTable' version false id column: 'myId' email column: 'theEmail' } } When trying to access either table, I get the error message "Invalid columnname 'user_id'" How do I define the foreign key column when using a legacy table? Without the association accessing both tables woks without any problem. Regards, Dirk --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
hasOne is used to put the foreign key in the "other" object's table, so in your current setup the foreign key is trying to be accessed from the Data table, hence the "user_id" format. Change User to:
class User { def name Data data ... } if you want the foreign key to reside in the User table. Brian On Thu, Aug 12, 2010 at 11:00 AM, Dirk Szameitat <[hidden email]> wrote: Hi all, |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by Dirk Szameitat
How did you solved it? I am facing same probelem
|
|
please try next thing
class Data { def email static belongsTo = [user: User] static mapping = { table 'DataTable' version false id column: 'myId' email column: 'theEmail' user column: 'userId' //whatever column name in DataTable table } }
Thanks
Grygoriy Mykhalyuno www.grygoriy.com |
| Powered by Nabble | Edit this page |
