What's best practice for querying multiple tables and foreign keys?
For instance:
User has many Tasks has many Reminders
I would assume best practice would be to keep foreign keys to their direct relatives, ie:
tasks table: id, user_id
reminders table: id, task_id
...to avoid situations where you have a bunch of foreign keys connecting tables to all possible relatives.
Let's say I want to retrieve all of a user's reminders.
SELECT reminders.* FROM users
LEFT JOIN tasks ON users.id = tasks.user_id
LEFT JOIN reminders ON tasks.id = reminders.task_id
WHERE tasks.user_id = {#YourUserIdVariable}
Is there a point at which doing joins to retrieve a record outweighs the integrity of the db? (assuming that storing reminders.user_id would be a bad practive in the first place?
5 tables? 10?