How can I design Jhipster JDL relationship for a simple Region > Country > State > City dropdowns - jhipster

I couldn't figure out how to make relations between entities make them depended each other.
Is jdl itself enough to have entities like below;
Add New Region:
Region Name
Add New Country:
Region (Dropdown)
Country Name
Add New State:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State Name
Add New City:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State (Dropdown "List updates with the change of the Country)
City Name
Add New Address:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State (Dropdown "List updates with the change of the Country)
City (Dropdown "List updates with the change of the State)
Address
I've tried this;
entity Region {
regionName String required
}
entity Country {
countryName String required
}
entity State {
stateName String required
}
entity City {
cityName String required
}
entity Address {
addressLine String required
}
relationship ManyToOne {
Country{region(regionName)} to Region,
State{country(countryName)} to Country,
City{state(stateName)} to State,
Address{city(cityName)} to City
}
paginate all with infinite-scroll
service all with serviceImpl
This jdl shows only it's parent. I want to create a new address entity with all parents up to region.
If I try to make relationships with all parents, all dropdowns are individual. You can select Asia > USA > Paris.
What is the right way to relate the address with Region, Country, State, City with correct dependencies?

The JDL looks good to me, it's just that JHipster won't generate the client view with transitive relationships. You have to write it manually.
On server side, you can use DTOs to combine all data in one request. Add dto * with mapstruct to the bottom of your JDL and then edit generated mappers.

Related

afterUpdate listener in typeorm does not listen to updates on #UpdateDateColumn - postgres DB

I'm working on a functionality, where in I have an entity called 'Employee' with a few columns like first name, last name, DOB, etc. and two columns:createdAt and updatedAt defined with #CreateDateColumn and #UpdateDateColumn respectively.
My requirement is that, whenever an update operation is performed on this entity, I should be logging the column name that was updated, along with the old and new value that it holds.
I'm performing the update on Employee table using queryRunner.manager.save()
To track the changes,
I'm making use of the entity subscribers 'afterUpdate' event.
Now on performing an update, for e.g. When I change the Name, my Employee entity is correctly updating the name as well as the 'updatedAt' field to current timestamp in DB
However,my 'afterUpdate' listener is only logging the 'name' column with its old and new values.
Its not logging the updatedAt column.
Can anyone please help me understand what's possibly going wrong here?
Entity definition:
...All columns (first name, etc.)
#UpdateDateColumn({name:'updated_at',type:'timestamp',nullable:true})
updatedAt:Date;
Subscriber code:
#EventSubscriber()
export class EmployeeSubscriber implements
EntitySubscriberInterface<EmployeeEntity> {
constructor()
{}
listenTo() {
return EmployeeEntity;
}
afterUpdate(event: UpdateEvent<EmployeeEnitity>){
const {updatedColumns, dataBaseEntity,entity}=event;
updatedColumns.forEach(({propertyName})=>{
//Get the updated column name and old and new values
//col_name = propertyName;
//oldVal= databaseEntity[propertyName as keyof EmployeeEntity] as string,
//newVal= entity?.[propertyName as keyof EmployeeEntity] as string,
})
}
}
I tried using different save operations (via repository, queryRunner, manager), but it didn't work.
Official docs say the event is triggered only on save operation.
If I manually pass the date to updatedAt field, then I am able to get the field within the event handler, but I don't think that's the right approach as manual intervention should not be needed for #UpdateDateColumn

odoo13 error creating new product public category (eCommerce)

I have a problem after deleting a product parent public category. Now, to create a new public product category, I get the following error:
The post is missing or has been deleted.
(Entry: product.public.category (682,), User: 2)
Where 682 is the primary category database ID that was deleted.
I've deleted all public categories, but the error is repeated.
How to solve this?
I attach a screenshot.
Screenshot

AutoMapper - Retrieve a different field from a linked source table than the one that links it

I have the following table structure that mixes legacy fields with an updated schema:
Coaster
Id (Int)
ParkId (Int)
Park
Id (int)
UniqueId (Guid)
So, the Coaster and Park tables are linked using the Park.Id field. The UniqueId field is not currently used in the old schema. We are migrating to a clean DB using AutoMapper, and this new schema looks like this:
Coaster
Id (Int)
ParkId (Guid)
Park
Id (Guid)
The problem I am having is doing this using AutoMapper. I've been experimenting with this code:
private ModelMapper()
{
Mapper.Initialize(x =>
{
x.AddProfile<ConvertersMappingProfile>();
});
}
// This is the part that I'm trying to work out
public ConvertersMappingProfile()
{
CreateMap<Park, NewSchema.Park>()
.ForMember(dst => dst.Id, map => map.MapFrom(src => src.ParkId));
}
In the new schema, the Park table's Id matches the old schema's UniqueId.
My question is: Because in the old schema there is no direct link to the UniqueId value of the Park table, how to do I get that value to map to the new schema using the Coaster.ParkId field to Park.Id field mapping?
I used a custom resolve to fix the problem. So I created my resolver, which pulls up a list of the items in the database (which is typically pretty small) to get all the values from the table I need, and retrieves the value. (Pre-refactored code):
public class ParkResolver : IValueResolver<Original.Park, New.Park, string> {
public string Resolve(Original.Park source, New.Park dest, string destMember, ResolutionContext context) {
List<Original.Park> list = new List<Original.Park>();
using (IDbConnection con = new SQLiteConnection(#"Data Source=C:\Users\Me\Documents\Parks.sql;")) {
con.Open();
list = con.Query<Original.Park>($"SELECT * FROM Parks WHERE Id = {source.ParkId}").ToList();
con.Close();
}
return list.FirstOrDefault().UniqueId;
}
}
And I call my custom resolver for the tables I am mapping:
CreateMap<Original.Park, New.Park>()
.ForMember(dst => dst.ParkId, map => map.MapFrom(new ParkResolver()));
Hopefully that will help someone else.

Force database tablename for collection relationship in Sails

In a sails project, considering a model User and a model Role, with a relationship between User and Role :
// `User.js
module.exports = {
attributes: {
...
roles: {
collection: 'role',
dominant: true
},
...
}
}
For the the database representation, sails/waterline will create following tables :
table user,
table role,
table like user_roles__role_roles_role to represent the collection
I know we can force the name for the models USER and ROLE
(with the property 'tablename' : http://sailsjs.com/documentation/concepts/models-and-orm/attributes).
But how can we force the name the relationship table ? (Especially this name is quite long and tends to exceed limit).
Assuming this is a two-way relationship, and the Role model has a users collection, Sails will expect a table named role_users__user_roles, which has the role id first, user id second.
Your example table name would require User to be dominant and would require the Role model to have an attribute named roles_role that is a User collection.
To create your own join table, you can use the through association method and add a new model that represents the relationship, perhaps UsersRoles, and specify the tableName in that model definition.
Examples of the through association:
sails
docs
similar question
gist from comments in that question

How to create an entity's relationship to itself? For example, hierarchical folders

I'm trying to create a hierarchical folder structure. Here's my Folder entity:
$ yo jhipster:entity Folder
The entity Folder is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? parentId
? What is the type of your field? Long
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
parentId (Long)
Generating field #3
? Do you want to add a field to your entity? No
=================Folder=================
name (String)
parentId (Long)
I'm trying to map out just what I need to provide jhipster's entity generator to make it work. This is what I have so far...
Generating relationships with other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Folder
? What is the name of the relationship? parent
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? child
Am I on the right track? How do I create the child many-to-one relationship? I get a warning if I try to create it with the Folder entity. There's no way to generate it afterwards.
You can use https://jhipster.github.io/jdl-studio/ for writing as jdl for creating entities.
Please visit https://jhipster.github.io/jhipster-uml/#jdl for more information.
This is a sample JDL that has relationship to itself :
entity RankProperties {
rank Integer required,
minExp Integer required,
maxExp Integer required,
maxStamina Integer required,
maxAlly Integer required,
maxTeam Integer required
}
enum TaskMode {
NO_CONTINUE_STAGE_COUNT,
STAGE_COUNT,
STAGE_ID
}
entity Task {
taskMode TaskMode required,
value Integer required
}
relationship ManyToOne {
Task{parent} to Task
}
dto all with mapstruct
service all with serviceClass
I recommend to use jdl model.
entity A { property1 String }
relationship OneToMany {
A{sons} to A{parent}
}
The model generates a Entity java class like (some annotations ignored):
class A {
#OneToMany(mappedBy="parent")
private Set<A> sons = new HashSet<>();
#ManyToOne
private A parent;
}

Resources