I have a bunch of new entities defines but I want have a #OneToMany from User to one of these entities. Do I have to code it manually inside User or can I do it with the JDL studio ?
User entity is an special entity. As you can read in the JHipster documentation, not all types of relationships are allowed with User.
Tip: the User entity
Please note that the User entity, which is handled by JHipster, is
specific. You can do:
many-to-one relationships to this entity (a Car can have a many-to-one relationship to a User). This will generate a specific
query in your new entity repository, so you can filter your entity on
the current security user, which is a common requirement. On the
generated Angular/React client UI you will have a dropdown in Car to
select a User.
many-to-many and one-to-one relationships to the User entity, but the other entity must be the owner of the relationship (a Team can
have a many-to-many relationship to User, but only the team can
add/remove users, and a user cannot add/remove a team). On the
Angular/React client UI, you will also be able to select a User in a
multi-select box.
When using the UAA authentication type, you can only create
relationships to the User entity if the related entity is also within
the UAA microservice.
Related
First of all i'm new to Jhipster, i've read the official documentations but i still can't seem to find a solution to my problem (i've been stuck for almost 3 weeks now), that's why i decided to ask here for help.
So, i have an application where i need to create an entity called employee and i need to create a user account with the additional fields taht are specified in the employee entity, so in other words, when i fill the form to create a new employee that will not only create a new one but it will also automatically create a user account for that emplyee.
What i've tried doing up until now, is creating a new employee entity and link it with a OneToOne relashionship to the USER entity (created by Jhipster) but the thing is, in that case i would have to create a new user and then add the additional information for the employee, wheareas i need it to be in the same form, to create an employee and the user linked to it at the same time.
Any help will be really appreciated.
What you want to do is not supported off the shelf by JHipster, you have to code it manually.
In backend, you could do it by defining a DTO that combines both entities, a RestController that exposes it and a service that is responsible for orchestrating persistence.
In frontend, it's the same you have a component that contains the form to update this DTO and call your REST API.
Alternatively, if a User is always an Employee, you could also merge them in a single User entity.
Of course, this depends on which authentication type you selected which defines where users are managed.
I am modelling user management domain where I have to address domain activities such as registration, login, role management etc.. I have come up with below aggregates.
When user registration is approved, I have to add an entry into users table and then persist his roles
Users <<root>> ----> User Roles (child entity)
New roles can be created by choosing appropriate privileges
Roles <<root>> ----> Role Privileges (child entity)
Privilege master table
Privileges <<root>>
My questions is, in the User Roles (child entity) of Users aggregate, can I have role_id which links to Roles aggregate root?
If I have to persist user roles, the business invariant is to make sure the roles are valid roles and hence I have to validate role_id against role master. So in the same transaction, can read data from another aggregate? Please note that, these aggregates are in the same microservice.
Thanks for the help.
Define "links".
It's perfectly OK for an aggregate to refer/link to another aggregate root by a stable identifier (e.g. a string ID). You can then use that ID to request another aggregate (e.g. from a repository). With that other aggregate you can perform reads, but should never perform updates.
Remember that aggregates define consistency and transactional boundaries. The aggregate you get need not be the latest version of that aggregate: it's a version of that aggregate from some point before you requested it (hopefully it's the latest version as of when you requested it, but that might not always be the case) and it cannot reflect changes since you requested it.
However, if your reference/link is through something more direct, then those consistency/transactional boundaries are violated, so that's generally not allowed (or at least not a good idea, as you're giving up other benefits of DDD).
I just started a project with the code generator "Jhipster". I'm trying to make a OneToMany relationship with the "User" relationship. I've looked at a lot of topics already but I can't find any working answers. Do you have any ideas? I even tried to go through an intermediate relationship but nothing works.
Thank you very much.
You can create relationships between your model entities and the special entity User. But you have to take into consideration the restrictions of this entity. As it appears in the JHipster documentation:
Tip: the User entity
Please note that the User entity, which is handled by JHipster, is
specific. You can do:
many-to-one relationships to this entity (a Car can have a many-to-one relationship to a User). This will generate a specific
query in your new entity repository, so you can filter your entity on
the current security user, which is a common requirement. On the
generated Angular/React client UI you will have a dropdown in Car to
select a User.
many-to-many and one-to-one relationships to the User entity, but the other entity must be the owner of the relationship (a Team can
have a many-to-many relationship to User, but only the team can
add/remove users, and a user cannot add/remove a team). On the
Angular/React client UI, you will also be able to select a User in a
multi-select box.
When using the UAA authentication type, you can only create
relationships to the User entity if the related entity is also within
the UAA microservice.
Other stackoverflow answers and bug reports have discussed setting a one direction relationship with the "user" entity but this won't work in a microservice using UAA authentication because there is no JHI_USER table in the schema.
You just can't because you're crossing service/system boundaries. Imagine you used LDAP or Active Directory to authenticate your users, the only thing you could do is to refer to a user by its login name which is basically an external ID. This is the same with UAA or between 2 microservices.
I'm using mongoose in my nodejs application, I have two Models: an Employee and Organization , I want to attribute some permissions to employees who belong to an organization like inviting or deleting other employees
I've created a mdoel ACL(_id,_empId,_orgId,[permissions]), but I'm not sure if will do the trick
What Models do I have to add in my database, knowing that I need just few permissions