laravel One to one relation with pivot table - many-to-many

hi Need some suggestions
I have three table
personal_details
vacancies
and a pivot table
personal_detail_vacancy
pivot table contains vacancy_id and the personal_detail_id (user who applied for a open vacancy) my problem is sending some personal_detail_id to a hotlists for a particular vacancy. so should i add status field in pivot table or create a hotlists table with one-to-one relation with pivot table . which one is better please help

I'm not sure what a 'hotlist' is, but if you need to set a flag on each record in the pivot table, you can create a boolean status column and access it like this:
$person = PersonalDetails::find(1);
foreach ($person->vacancies as $vacancy)
{
echo $vacancy->pivot->status;
}

Related

Link another table based on a column value

Hi, I'm designing a item catalog using MySQL and Squalize ORM (NodeJS).
Suppose I have a product list with different attributes based on its category (attributes_id in this case).
I would like to get a product by using a JOIN statement with an appropriate attribute table. The design should be scalable as we will have more than a hundred attribute tables.
Roughly the statement will look like this:
JOIN
if ( product.attributes_id == 1 ) 'attributes_car'
elseif ( product.attributes_id == 2 ) 'attributes_food'
BUT the the number of elseif cases will grow more than a hundred later.
So the question is how to design attributes_id? Is it a good idea to make it a foreign key to the database metadata (like INFORMATION_SCHEMA) to point to another table? Should I introduce another table to manage such relationship?
One of option is a Dynamic SQL but I don't think it is a good idea because the ifelse cases should grow.
Or should I give up designing a query and just implement such logic on NodeJS side using ORM?
Thank you!
One solution would be to create an additional table that stores attribute_id and table_name.
Create table attibute_tablename(
attribute_id int(11),
table_name varchar(25),
PRIMARY KEY (attribute_id, table_name)
)
You can also add a foreign key to the product table if you want.
Then you only need an insert to this table for every new item added

How to create database design to store product as a new product and popular product?

I have a one product table in MYSQL. Now i need to show product as new product and popular product. which is best practice to use these new fields. Should it add into same db table of products or need to create another new ? Do we need to create two separate table for this two new fields ? or can we use one table for this ?
What you can do is Create a new table lets say Product_Status and have fields as Status_Id and Status_Description.And in main table add a column as PStatus. Now what you do is you assign a number for the status you want to add in Product_Status table(ex: Status_Id=10,Status Description:New Product) .You can link the two table with foreign keys. and enter the status_id in the main table's PStatus.

How to fetch data using One to Many relationship using MySql and joins in MySql

I am creating a demo application. I am stuck in a scenario, I am not getting the exact way and query to fetch data from sql database in the following scenario:
I have a table named RegistrationTable, this table has a column RegistrationId as its primary key. There is another table named ApplicationDetails, this table has a column ApplicationId as its primary key.
I have referenced ApplicationId as Foreign key to RegistrationId column.
My requirement is, single user can apply to multiple jobs. job details will be present in ApplicationDetails table.
How can I check to how may jobs the user has applied based on his email id stored in registration table.
I have a column Status in ApplicationDetails table, where as soon as user applied to a job I am updating the status column.
I am trying the following query but its not working:
SELECT Status FROM ApplicationDetails
INNER JOIN RegistrationTable ON ApplicationTable.ApplicationId = RegistrationTable.RegistrationId
WHERE RegistrationTable.EmailId = "abc#xyz.com";
Can any one please suggest me how can I go about this. I am a beginner to SQL. Please do suggest a way to solve this. Thanks in advance.
You need to change the table name in your query to ApplicationDetails. This is what you mentioned in your post
SELECT Status FROM ApplicationDetails
JOIN RegistrationTable ON ApplicationDetails.ApplicationId = RegistrationTable.RegistrationId
WHERE RegistrationTable.EmailId = "abc#xyz.com";

how to create table column that is a list of items from another table

I need to make a database table for a small invoice app i am making, and I made a table called "Invoice" which stores all my invoices. It has a column called "items" which should be a list of items invoiced to the customer. i.e. "Camera, film, lens".
The items are located on another table called "Items" which has "item_name" and "Item_id".
How can I make the "items" column in "Invoice" store a list of Items?
Thanks
Do some research on Foreign Key and try to implement them on your scenario.
You need to join your tables. You will do this using Your Primary Key of one table and a foreign key in another. Use the below formula.
'SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;'
You will then use the below formula to select your data into a new table.
'SELECT *
INTO newtable [IN externaldb]
FROM table1;'

Pick Linked table named as an input table in the append MS query

I need to append the data to a Access Table ULAE. I wants parameters to be picked from another table LAE.This table has 4 columns(Group,le,qtr,Table name) that will be an input and some parameters will be part of where condition. However there is one column table name that will have linked tables. Is it possible to pick the table name (that would be a linked table in the same access file, from where the data would be appended to ULAE).Is it possible to implement this in MSquery?
What i need is to pick the table name from LAE and append the data into ULAE from the table name specified in the LAE.
my query is like
INSERT INTO ULAE( vdate, profile_id, le, ibu)
SELECT PERSIAN.vdate, PERSIAN.profile_id, PERSIAN.le, PERSIAN.ibu
FROM **PERSIAN**;
**Persion is the linked table name coming from LAE**
Thanks in advance.