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

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.

Related

Strapi add extra field in the relationship table

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?

Inheriting Parent Table with identifier (Postgres)

Sorry if this is a relatively easy problem to solve; I read the docs on inheritance and I'm still confused on how I would do this.
Let's say I have the parent table being car_model, which has the name of the car and some of it's features as the columns (e.g. car_name, car_description, car_year, etc). Basically a list of cars.
I have the child table being car_user, which has the column user_id.
Basically, I want to link a car to the car_user, so when I call
SELECT car_name FROM car_user WHERE user_id = "name", I could retrieve the car_name. I would need a linking component that links car_user to the car.
How would I do this?
I was thinking of doing something like having car_name column in car_user, so when I create a new data row in car_user, it could link the 2 together.
What's the best way to solve this problem?
Inheritance is something completely different. You should read about foreign keys and joins.
If one user drives only one car, but many users can drive same car, you need to build one-to-many -relation. Add car_name to your user table and JOIN using that field.

MS Access Filter Child Table by Record Chose on Form

I'm trying to create a simple 2 table database - table 1 holds ClientInfo and table 2 has ClientVisits - Relationship is on ClientInfo.ID->ClientVisits.ClientID. Then I have a form created thus for viewing the ClientInfo plus a child(sub?)table which SHOULD show all the records from ClientVisits where my Form ClientID = ClientVisits.ClientID.
Here is my form
Here is the child table with fields shown
Relationships
So I already have one record in ClientVisits for the currently chosen ClientID form record. But it doesn't show in my Table.ClientVisits. Other than the relationship I don't have any other link between the ClientID and the ClientVisits.ClientID field.
If I need to post further info please let me know, trying to describe this as well as I can - sorry if it's not making sense. Thanks.
You have to link both tables in your form.
In my example, main data of my form is a table called CLIENTES, where it shows all the information about a cliente. It would be exactly the same as your table ClientDetails. In this table, primary key is a field called DNI (it would be the equivalent of your ID field)
I got a second table called CONSULTAS MÉDICAS. This table is just a list of how many times this client comes to see us. It would be the same as your secondary table CLIENT VISITS. In this table, I got a field called PACIENTE, linked to my table CLIENTES. Let me show you.
Ok, now my form is done based on the data of my table CLIENTES, but I got a subform control, where I have linked the table CONSULTAS MÉDICAS
To make this work is pretty easy. Not filters or queries. Just linked child and master fields. To do this, you have to select properties of your subform control, and then go to DATA TAB
Just choose as main field your ID field from table CLIENT DETAILS and link it to child field CLIENT ID from table CLIENT VISITS
That should work for you.

EF 1 include for several children

I'm using EF 6 to query my database. I have a structure when I have a table (sites) which has 4 associated tables (wages, waste, sales & availability) linked by site ID.
The sub tables then all have an association to a departments table.
I have disabled lazy loading for performance reasons. I was wondering if there is a way to query the sites table where I can include the 4 sub tables but not need to specify the include to the department table for each of these.
Thanks
Turns out that simply adding an include to departments from one of the four tables (wages etc) was sufficent.

Create Entity of specific columns

I am using Breeze (http://www.breezejs.com/) and to use the functionality I want it requires mapping to a complete entity and all of its fields. I have a "Person" entity, but it includes a Social Security Number field. I want to keep this SSN# field private so I would like to create an entity named SubSetPerson that is updateable, has navigation properties and only contains the columns I want (e.g. ID, FirstName, LastName, myNavigationProperty) and does not contain the SSN#. I am using database/model first. Is this possible?
If you are using database first, then you could create a view for that table which only selects the columns you want. Then update the EF model browser to include that view.
Try using a Master-Detail type structure for your person. The master table would contain the person's public information; ie name, birthdate, etc... The detail table would contain only the more sensitive information (SSN, etc...). Then depending on your needs you can load the detail or not.