last day (15 days later) » 

6:34 PM
0
A: Is it better to save database relation as value or id?

user1534664If you have comment_id as a primary key in completed_table, that means that each comment is uniquely defined per task. When you want to query the name of the task you can just join the tables on task_id. So task_id becomes a foreign key. So why would you not have accurate data when displaying th...

 
If they changed the name of an already completed task. That would not reflect the name of the task that they actually completed. So I guess the question is how to handle that, not how to store the relationship.
 
@Staysee So if I understand you correctly, you don't want the task_name to be changed? Or do you want the task to have multiple task names? The initial one and subsequent changes.
 
Im trying to figure out how to best handle a task_name change. Part of me feels like the task that they complete should be set in stone, so if they edit the name, it would not reflect the change when displaying the completed tasks.
 
@Staysee well, once you know what your system has to do (or what you want it to do), you can then define the database. If you want the task name to be "set in stone" you could have an initial_task_name and an updated_task_name in the tasks_table. If you just want one task name that can be changed, then your current database structure will suffice. It seems to me your problem really has to do with defining what you want your system to do, rather than how to structure a database.
 
Agreed, I was asking the wrong question. Thanks for your help.
 
6:34 PM
@Staysee Glad it helped :) You should really ask what the person wants who you're writing this application for.
 
It's actually an application that I am developing for myself, for practice. I am trying to figure out the best way to handle this situation.
 
Ah cool
 
What if a user deletes a task, but then they want to view tasks that were completed last year, that task would no longer exist.
 
Yeah that task would no longer exist in the database. So you should not allow the user to delete them.
 
It makes sense lock down a task that has been used, so that it cannot be deleted.
 
6:38 PM
Yeah, look what alot of forums do for example
they close a topic after the problem has been solved
but it still exists in the database so people can still view it etc.
 
A bigger problem is editing a task I think. I want to let them fix a typo or something, but if they totally change the task to something else. Then that would not be good for viewing historical data.
Right, so maybe a soft delete would work too.
 
Well in 99% of the cases it's fine to allow the user to edit the name of a task, because the comments that belong to the task will still be linked to that same task by task_id
I'm not familiar with soft deletes, but I guess you know what I mean
oh nvm
So a task can be either open, or it can be completed right?
I would add an attribute "IsCompleted" to the task
 
There is a page where you add all your tasks, to populate the task table. Then you can select certain tasks that you will complete that day. So the relation table is needed. Everyday you could complete different tasks, but they are all pulled from the task table.
 
if I understood correctly from your question, the relation table was only needed because a task has multiple comments
 
Close, a task can be completed multiple times. I simplified the table for the example.
 
6:46 PM
Oh
I see
Yeah that changes things
 
Yea I can see how that is confusing, what I have in the question, my bad.
I think this is enough for me to ponder though, guess it all comes down to what I think is the best experience to the user.
 
yeah that's fine I've been there myself
exactly
in practice you always ask the person who wants the application built
what does he want?
once you analyse that you can start making designs like ERDs (database structure etc.)
then after you made the designs, you can start programming
after that comes implementing
so it's pretty much 4 steps that you should really master
 
Right, make sense. I started coding it then I was like... well what happens if they edit or delete.. crap!
 
Yeah that's the learning process though :)
At the start everything is pretty abstract
till you get a bit more experienced
and you start seeing what you've done wrong last time
and you'll reflect and think, what can I do better next time?
but you should really look into a few things I suppose
and that's how database structuring works
because I think that's why you thought this problem had to do with databases
and the paradigm I just explained to you
analysing -> design -> realisation -> implementation
If you get that down you can pretty much make any webapplication you want
 
Yea, well my original thought was whether not I should store the task_id, or the task_name. That way you can edit/delete tasks all you want, and I still have the original on the completed tasks.. haha
But yea, nothing to do with databases really.
 
6:53 PM
yeah I think your problem is solved now
 
Agreed. Thanks for your time.
 
I started understanding about databases properly
when I read up about ERDs
took me a couple of weeks, but then it started making sense
I guess you already have some OOP up your sleaves
no problem
Good luck
 

last day (15 days later) »