Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL & Templates: Supporting Multiple UniqueConstraint for entities #176

Open
zhongweijun opened this issue Apr 29, 2015 · 3 comments
Open

Comments

@zhongweijun
Copy link

In some cases we need to define multiple UniqueConstraint for entities. For example, we have a User entity which have 4 attributes -- id, userName, mobileNumber, email. Apparently the field id is the identification for a user, and the userName, mobileNumber and email is not.

Here a requirement comes. Though the userName, mobileNumber and Email is not an entity identification, we still want the user could login the system by either his userName, mobileNumber or email. It means, the userName/mobileNumber/email could identify a user. In this case, we need a multiple UniqueConstraint for these 3 fields.

Entity User {
    Long id key;
    - @Username userName;  // basic type
    - @MobileNumber mobileNumber;  // basic type 
    - @Email email;               // basic type
    - @Password password;  // basic type
}
@zhongweijun zhongweijun changed the title Templates: Supporting Multiple UniqueConstraint for entities DSL & Templates: Supporting Multiple UniqueConstraint for entities Apr 29, 2015
@tjuerge
Copy link
Member

tjuerge commented May 6, 2015

As a side note: The attribute "Long id key" is not valid here because this id attribute is added to every persistent domain object during model enrichment.

Regarding the id attribute Patrik stated in a forum post the following:

In Sculptor the id property has some very special meaning. It is always an autogenerated value. Used as primary key and foreign key relations.

@tjuerge
Copy link
Member

tjuerge commented May 6, 2015

As mentioned in a forum post this could be worked around via a gap class or by using the hint keyword and overriding DomainObjectAttributeAnnotationTmpl.columnAnnotations() via Sculptors extension mechnism.

@tjuerge
Copy link
Member

tjuerge commented May 7, 2015

How about using a single @UniqueConstraint with multiple columns?

Entity User {
    - @Username userName key;
    - @MobileNumber mobileNumber key; 
    - @Email email key;
    - @Password password;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants