在这种情况下我该如何决定我的领域模型?
我需要开发一个应用程序用于IT项目中的用户管理。这样做是为了学习 Grails。我有一些问题要开始:
在我的示例应用程序中,用户有很多任务,属于一个项目,有很多假期状态,属于资源规划,仅此而已。 (某种要求!)
现在......说到领域建模,我实际上是如何建模的?我想出了这样的建模解决方案:
class User {
//relationships. . . .
static belongsTo = [ company : Company, role : Role, resource : Resource]
static hasMany = [ holidays : Holiday, tasks : Tasks ]
Profile profile
Project project
String login
String password
static constraints = {
login(unique:true,size:6..15)
profile(nullable:true)
}
String toString() {
this.login
}
}
现在利用 Grails 脚手架。我生成了视图,嗯,这就是我震惊的地方!
有了这个模型,显然在创建新用户时,我需要放弃项目详细信息、资源详细信息。即使我可以根据需要更改视图,例如,我只需要两个字段(即新用户的登录名和密码)即可注册我的网站。但根据数据建模,我如何处理其他字段,如配置文件、项目和其他关系。这听起来很复杂!我知道我是网络开发的新手,我想要您的建议以及我该如何继续?
提前致谢。
I need to develop a application for a user's management in a IT Project. This is done in order to learn Grails. I have some problem to start with :
In my sample app, a user has many tasks, belongs to a project, have many holiday status, belongs to the Resource planning and thats it. (kind of requirements!)
Now..... When it comes to domain modeling, how I actually model this? I came up the solution of modeling something like this :
class User {
//relationships. . . .
static belongsTo = [ company : Company, role : Role, resource : Resource]
static hasMany = [ holidays : Holiday, tasks : Tasks ]
Profile profile
Project project
String login
String password
static constraints = {
login(unique:true,size:6..15)
profile(nullable:true)
}
String toString() {
this.login
}
}
Now taking advantage of Grails scaffolding. I generated the view, hmmm well thats where I got struck!
With this model in place, clearly when creating a new User., I need to give away project details, resource details. Even though I can change the view as I need, for example I need only two fields say login and password for the new User to register my site. But as per data modeling, how I can handle other fields like Profile, Project and other relationships. This sounds complicated! I know i'm a newbie to both web development and I want your suggestions and how do I proceed with this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要覆盖控制器中的
save
操作并填写其中的其他字段。尝试在 UserController 中添加以下代码:
获取默认项目的方法的实现取决于您的应用程序的逻辑。
You need to override the
save
action in your controller and fill those additional fields there.Try adding the following code in UserController:
The implementation of methods to get the default project depends on your app's logic.