Relating two tables with foreign key

Relate two database tables when one lacks a matching primary key.

Overview

The issue occurs when trying to link a custom table to the Joomla users table without a common unique identifier like the user ID.
Add a user_id field to the custom table to store the Joomla user ID, then define the foreign key relationship using this field, selecting the 'multiple matching' relation type if needed.

Answered
Connectivity v6
kk kkurtz 01 Jan, 2018
I am trying to relate two tables: one is the Joomla users table (primary key is id) and the other is a user information table. Both tables contain the username. But I don't want to make the primary key the username in the information table because I need to allow multiple records for some of the usernames. How can I use the foreign key to match the two tables? I would rather not force the second table to have the id field if I can help it.

Thank you,
Karen
Max_admin Max_admin 04 Jan, 2018
Hi Karen,

The usual setup is to have the 2nd table have a field named "user_id" which contains the user id from the first table, then you can use user_id as the foreign key and select the relation type as "multiple matching" if you are going to have multiple records per user.

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kk kkurtz 05 Jan, 2018
Answer
1 Likes
So I guess I'll have to find a way to add the user_id to my second table.

Thanks, Max
This topic is locked and no more replies can be posted.