Strapi add extra field in the relationship table - postgresql

I am using Strapi for my application. I am using Postgres as a database. There is user table. I want to create a Teams table linked with Team Leaders and Team Members related to users table. I added team name, team code, and Team Leaders(Relationship field -> Many to Many Relationship), Team members(Relationship field -> Many to Many Relationship)
After I did this, My table fields look like this,
Teams,
Id, name, code
teams_team_leaders__users_team_leaders
Id, Team id, User id
teams_team_members__users_teams
Id, Team Id, User id
But here I wanted to add one extra field (custom_role) in the teams_team_leaders__users_team_leaders and teams_team_members__users_teams table. Is there any way to add a new field/column into Relationship tables?

Related

How do I add data from parents to child table Postgres?

I have 3 tables:
What I have: 2 pages;
ONE where an admin can add a project's name and the id will be autogenerated and
TWO (currently working on) Add and user with its name, ID to the USERS table, and select a project from the PROJECTS table, so after it gets added, display that info, either the users and the projects they belong to, or the projects and the users it contains.
In this page I am already displaying the projects from the PROJECTS table in a checkbox, since they can belong to several projects, but I need to display: userName, projectName and probably later the IDs, in a table when they get added.
How can I add that info to the child table and show the columns values from its parents tables? projectName and userName
Any help and suggestions are highly appreciated.
PS: I'm not good with databases so I'm probably missing something obvious here.
Better to use userId from "users" table as FK in "projects" table.

DB Normalization for Users and Roles with different attributes

What would be the correct way to normalize a scenario where we have Users and Roles where certain roles have the same attributes and other roles have different attributes? Let's take the following example:
tb_User(user_id, first_name, last_name, e_mail);
tb_Role(role_id, role)
tb_Plant(plant_id, plant)
tb_Entity(entity_id, entity)
I have roles like: Admin, General Manager and Plant Manager and Entity Manager. Admin and General Manager roles don't have any other attributes, but plant manager has a plant associated with it and Entity Manager has an entity associated with it. Should I create one table like this and have Plant/Entity have a value where it applies like this:
tb_user_role(user_role_id, user_id, role_id, plant_id, entity_id)
or have separate tables for plant and entity like this:
tb_user_role(user_role_id, user_id, role_id)
tb_user_role_entity(user_role_entity_id, user_role_id, entity_id)
tb_user_role_plant(user_role_plant_id, user_role_id, plant_id)
Another consideration is that one one user can have many plants, so one plant manager role and many plants, same thing for entity.
I appreciate your help,

MongoDb conditional relationship

Suppose I have following 4 collections:
1- posts
2- companies
3- groups
4- users
Bellow is my current structure in post:
and their relation is:
A company has an owner and many other members (user collection).
A group has many members (users).
A user has many posts.
A group has many posts that published by one of its members.
A company has many posts that published by its owner or members.
Now i have a problem on storing relation of users, company, and group with posts collection.
Bellow is my current structure:
I have decided to have a field postable inside my post document, and has a type field that will be 'user', or 'group', or 'company', and two other fields name, and id that will be company/group id and company/group name in cases that post is belonged to company or group but not user means type="group" || type="company".
Now how i can handle this to map id as FK of group and company collection (one field FK of two collection) ?
Is it the right structure ?
What you have here is a polymorphic association. In relational databases, it is commonly implemented with two fields, postable_id and postable_type. The type column defines which table to query and id column determines the record.
You can do the same in mongodb (in fact, that is what you came up with, minus the naming convention). But mongodb has a special field type precisely for this type of situations: DBRef. Basically, it's an upgraded id field. It carries not only the id, but also collection name (and database name).
how i can handle this to map id as FK of group and company collection (one field FK of two collection)?
Considering that mongodb doesn't have joins and you have to load all references manually, I don't see how this is any different from a regular FK field. Just the collection name is stored in the type field now, instead of being hardcoded.

OO Design and the data model for change log function

: EJB 3, JPA (EcipseLink) and Oracle Database
An application has two entities: Group and Person. There is a one-to-many relationship.
The requirement is, that every changes of Group and Person must be saved for later to roll or show.
The 1st idea:
make the id and timestamp of the change/create as a composite primary key for Group and Person.
Every change will create a new object with the same id and new timestamp. For Example, a Group hat been changed, then create a new Group. but the relationship between Group and Person unchange. Here hat a problem: the constrait "one-to-many" will breaked!. Now one person hat the relation to two groups with the same id.
The 2nd idea:
for Group and Person create two another Entities GroupArchive and PersonArchive. In Group and Person only the lastest Infomation. Any changes will be copied and saved to Archive Entities. Between Group and GroupArchive hat a one-to-many relationship. And same for Person and PersonArchive.
Are my ideas realizable? Has anybody a better idea?

Defining Many-to-Many Association in Entity Framework

I have the following tables in my edmx :
Errors
Id, Description, solved, officeId, siteId
Sites
id, location, name , officeId
Offices
officeId, officeName
the mapping between offices to sites are 1-to-many(offices can have many instances of sites).
i want to create many-to-many association from Errors to Sites
so i can access Sites properties directly.
I always keeps error in mapping.
can someone guide me how to do it right?
thanks in advance
You don't need to ad foreign key properties like officeId in Erros table in the edmx. Instead of adding those add associations among entities(Right click on your entity and choose addnew-> associatoin ). When you are adding associations you can define the relationship (one to many,may to many ...).