Multiple similar entities or use the same one in core data? - core-data

So I've got a Client entity that needs a relationship to a PhoneNumber entity to allow multiple phone numbers. And I've got an Employee entity that also needs a relationship to a PhoneNumber entity to allow multiple phone numbers. Should I create two separate PhoneNumber entities or can I somehow use the same entity for both?

I would create a parent entity called Person for your Client and Employee entities. The Person entity would have a relationship to the PhoneNumber entity.
Inherited entities have the same attributes and relationships as their parent entity. Of course you can add attributes and relationships to the "child"-entities as well. I omitted that in the screenshot.
Something like this:
you can configure the parent entity in the core data inspector in the right side pane.

Related

How to dynamically configure relation with different entities depending upon column property

How to configure User entity, to have OneToOne() relation with Profile entity with a extra condition. ie
if the User type is TYPE_A, then the User entity should have relation with ProfileA
or
if the User type is TYPE_B, then the User entity should have a relation with ProfileB
and so on...
Is it possible to achieve something like this?

Update the Jhipster User entity

I use jhipster and I would like to modify the User entity and add fields and relationships.
I use jhipster entity user and this command is not good.
How can I do it?
User is not a JHipster entity, the generator does not manage it. You must edit the code manually or add a related entity where you put additional fields, see doc: https://www.jhipster.tech/tips/022_tip_registering_user_with_additional_information.html
If you encounter a problem where you need to alter the User entity, Its recommend not doing that. Modifying this default entity might break your app depending on the nature of the changes.
Instead, there are other available solutions like:
creating an entity composed of the User entity
extending the User entity
Using composition
by using OneToOne relation like this
entity ApplicationUser {
additionalField Integer min(42) max(42)
}
relationship OneToOne {
ApplicationUser{internalUser} to User
}
Or
Using inheritance
This solution does the same thing as the previous one, but isn’t as straightforward as the first one because you need to:
create a new entity by hand,
adapt the code to make it use this new entity,
potentially manage yourself the database migration to persist this new entity (depending on the nature of the changes).
More info: https://www.jhipster.tech/user-entity/

Jhipster : How to generate code for list of Entity / Plural Entity

Let's say I have an entity Book
I want Jhipster to generate a Books Entity something like
class Books{
List<Book> books;
}
And Generate corresponding rest controllers like
Books saveAllBooks(Books books)
Books updateAllBooks(Books books)
There's no need to create a Books entity if it contains only a list of Book entities, you could just add manually the list methods to generated REST controllerBookResource.java as you don't need any additional repository.
But if Books has other fields that you want to persist in database, you could generate 2 entities with one-to-many relationship. I wouldn't recommend using plural as it could probably conflict with other generated code.
entity Book{
title String required
}
entity BookBatch{
name String required
}
// RELATIONSHIPS:
relationship ManyToOne {
Book to BookBatch
}

Field not allowing loupe. gvnix 2.0.0.M1

We have two child classes: Child1,Child2 that inherits from the same a class ParentClass, and only the class ParentClass.
We have a class A that contains a field parentList of type set field. This parentList is a list of ParentClass instances Ids
private Set parentList = new HashSet();
What we really want to achieve, is to select multiple values from either Child1 and Child2, and assign them to the parentList set field in class A, using Loupe.
When we try to execute the loupe command over the parentList field of class A, we get the following error:
Field 'parentList' could not implement Loupe Field.
What are the restrictions on the fields to use Loupe?
Is what we want to achieve, possible?
This UI component is designed to handle relations between JPA Entities of type many-to-one in the many side of relation (field must be annotated with #ManyToOne).
Currently gvNIX doesn't include any component which handle #*ToMany relations the way you required. The most similar is the use of master-detail datatables (see web mvc datatables details add command). An example of this could be: master Vets and details Visits (selecting a Vet related Visits will be shown in details list).
The component you need can be done but you must create it by hand.
Good luck!

In JHipster how to create entity with relationship with User?

I need to create my own entities using the JHipster using the command "yo jhipster:entity myEntity" that have many-to-one relationship with the User entity that comes by default in JHipster.
I have tried unsuccessfully to create in the wizard a relationship with the entity "user" and the field "login" but it is not working.
What is the good way to do this with JHipster? Or do I have to create the entity without JHipster tool (but I need the CRUD!).
Thanks,
Yann
Just an update - jhipster 2.5.0 was released a few days ago adding support for this. Created this answer since the formatting in comments make i pretty hard to read.
When creating a relation for your entity simply answer the questions like this
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? user
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with AngularJS, which field from 'user' do you want to use? login
Possible values on how to display the relation could be: id, login, first_name, last_name, email
See https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html for moreinformation
Just to add to the correct answer by #stoffer, if you're using the jdl it will look like:
relationship ManyToOne {
Owner{user(email)} to User{owner(name)}
}
at a good sample in an official document is say :
entity Blog {
name String required minlength(3),
handle String required minlength(2)
}
relationship ManyToOne {
Blog{user(login)} to User
}
jdl-samples/blog.jh
If you are using the 1.x version, this wasn't made to work, so basically you should do it by hand, without the generator (but it is definitely doable).
For the 2.x version, we have refactored the User object to have an ID field -> this should make this a lot easier, but as this is not released yet, we don't have a feedback at the moment.
I have come into this issue and solved it by using a simple one-to-one relationship first that will extend the user entity, because it is simple and manageable easily and can make the extended entity be the owner of the relationship, then you can create the many-to-one relationship with your entity, like this example:
entity MyEntity {
MyField Type
...
}
entity ApplicationUser {
additionalField Type
...
}
relationship OneToOne {
ApplicationUser{internalUser} to User
}
relationship ManyToOne {
MyEntity{appUser} to ApplicationUser{myEntities}
}
For more details and approach refer to this jHipster page.

Resources