4

我正在学习 Grails,我正在尝试构建一个小型应用程序。现在我正在做注册部分。

注册过程有 3 种不同的视图 1) 作为员工,我的注册视图因字段不同而不同 2) 作为雇主注册视图会有所不同,我将收集公司详细信息,可以代表公司行事的授权代表. 所以事实上,我认为公司(雇主)不是演员,但代表是演员,因此需要一个有代表性的领域类。3) 零售商注册视图不同。

所以我需要定义域类及其关系我对 grails 非常陌生,我需要一些设计指导

我最初考虑的是用户域类并有用户类型(它定义了不同类型的用户,例如代表、零售商和员工),但不确定这是否有效。

感谢有人可以帮助我构建我的域类。

谢谢

4

1 回答 1

1

You definitely want to map out your domain classes before you start working on the views. Is the authorized rep always going to be an employee, or is it a completely different entity?

Think of it in terms of objects, and try to mimic it as much as possible. A company has employees, and can have an authorized representative. Here's a sample mock up:

class Employee {
    String firstName, lastName /* etc... */
}

class Company {
    String name /* etc */

    Representative authorizedRepresentative

    static hasMany = [ employees : Employee ]
}

class Representative {

}

Of course, you may want to have references from the Employees back to its Company. Have a look at the Object Relational Mapping portion of the Grails docs.

于 2011-06-07T18:19:11.997 回答