Reputation: 10419
I have a a uni-directional 1:M.
A User can have many Carts. Before getting into a debate about ah this should be bidirectional, just assume I have to make uni-directional.
class User {
}
class Cart {
static belongsTo = [user: User]
static mapping = {
user joinTable: [name: 'cart_user']
}
}
I get:
org.hibernate.HibernateException: Missing column: user_id
Any ideas?
Upvotes: 0
Views: 46
Reputation: 10665
You are missing static hasMany = [carts:Cart]
?
So try this (uni-directional):
class User {
static hasMany = [carts:Cart]
}
class Cart {
static belongsTo = [user: User]
}
update: To make it bidirectional
class User {
static hasMany = [carts:Cart]
}
class Cart {
User user
static belongsTo = [user: User]
}
Upvotes: 3