The code can look like (with one-to-many relations: Major can have many Students):
class Student{
Long id
String first_name
String last_name
static belongsTo = [
major_code_1: Major
, major_code_2: Major
]
static mapping = {
table 'Student'
}
}
class Major{
Long id
String description
static hasMany = [
student_1: Student
, student_2: Student
]
static mappedBy = [
student_1: 'major_code_1'
, student_2: 'major_code_2'
]
static mapping = {
table 'Major'
}
}
But could you please explain me the idea of this two tables. Because it looks like recursive relationship many to many between Major Entity which is called Student. I wonder if you shouldn't have student_code_1 and student_code_2 in the Major table.
-------------------------------- EDIT ------------------------------------------------
With many-to-one relation (Many Students have the same Major)
class Student{
Long id
String first_name
String last_name
Major major_code_1
Major major_code_2
static mapping = {
table 'Student'
}
}
class Major{
Long id
String description
static belongsTo = [
student_1: Student
, student_2: Student
]
static mappedBy = [
student_1: 'major_code_1'
, student_2: 'major_code_2'
]
static mapping = {
table 'Major'
}
}