I'm not sure how to articulate this correctly so here it goes.
I'm designing a small webapp and in my database I have a table for users
, commits
, and userCommits
. it's pretty minimal as in users
has an ID that is auto number as well as commits
has a similar ID column. Now userCommits
is what links them together as you can see in the following figure.
What I've done is INSERT INTO commits (...) VALUES (...)
but the problem with that is how do I create the link in userCommits
so that userCommits.commitID
will equal the correct commit. I feel like I shouldn't just query the table to find the latest one and use its ID. Is there a way to join the ID's somehow?
I know that I can do a query like this to list all the commits the user via email.
SELECT
commits.id,
commits.cName,
users.email
FROM
commits
INNER JOIN userCommits ON commits.id = userCommits.commitID
INNER JOIN users ON userCommits.userID = users.id
WHERE users.email = "someonecool@hotmail.com"
But what I'm now trying to do is to insert into the database when the user creates a commit.