Adapting design to Grails
-
28-05-2021 - |
سؤال
I've finished a php/mysql CMS project, and since grails is the main subject for one of my classes, I figured why not play around with it some more and adapt the CMS to a grails app.
I'm currently modeling the domain, which consist of 4 classes: User
, Labs
, Files
and Support
. The User
is the main domain of the app and has many Labs
. Each Labs
object has many Files
and a single Support
.
The goal of Support
is to reference all the Users
that are attached to a particular lab. Each lab has a lead, staff of 0 to many and a faculty advisor. My problem is how do I model this in Grails? I'm currently declaring a User lead
and User faculty
in the class, but am not sure how to manage 0 to many support staff.
If I do a static hasMany [user:User]
, this means that any User
attached to the Support
will be added without a distinguishing role.
Any suggestions?
المحلول
I think it's just calling the relationship staff.
class Support{
static hasMany = [ staff : User ]
User lead
User facultyAdvisor
}
In your code then, you will call:
def support = new Support()
support.addToStaff( user1 )
which makes sense to me.
Your hasMany can be called anything. You can even have a relationship like
class Support{
static hasMany = [ staff:User, leads: User, facultyAdvisors: User ]
}
and this will allow you to distinguish the users by role.