last day (22 days later) » 

6:42 AM
0
A: Laravel relationships between 3 different tables

Dov Benyomin SohacheskiDatabase Scheme Schema::create('tasks', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->timestamps(); }); Schema::create('sub_tasks', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->string(...

 
so only problem is that the sub tasks will have different inputs. Taking your example let me revise. 1 sec.
 
PHP is very goof at assuming variable types, you should have any issues: ("1" == 1) in PHP
 
check out the answer i gave below.
 
@Citti: what are you planning on doing when a task3 comes around, create another table?
 
yea that is my thought. They will be custom fields anyways right? Is that not the way to approach it?
 
6:42 AM
Not at all. The schema I posted is the way to go
 
but wont i end up with a bunch of NULL values in the sub task table? If i have 3 sub_task fields that only apply to Task 1 and then 5 sub_tasks that apply to Task2 ... ill end up with a ton of NULL fields... or am i missing something...
 
You are missing a lot: the relationship between tasks and sub_tasks is one-to-many. Meaning one Task will have many Sub-Tasks and none of them will be null
 
added more examples as an answer... still not making sense to me. let me know if that makes sense... Expanded on what i had.
 
I just updated the answer
 
good call ;)
ok let me check that out.
Ok i see where you are going with what you are saying... What i was trying to illustrate (horribly apparently ;) ) is that it is not as simple as title|description ... Each "task" or just think of it as a game... has multiple inputs for a post.
are you familiar with destinyLFG.com?
take them as a task1... or Game1 .. then they added on "task2" or "call of duty" -> the inputs needed to create that "post" are different. and i dont see a way of storing them in the same table...
a post for a destiny game help... needs things like character level or light level etc. Call of duty might ask completely different questions...
now with that all said. I might have 4 or 5 or 20 games at some point... and would still want to be able to pull one master list of posts... for all games... Does that clarify this at all?
@DovBenyominSohacheski
 
6:55 AM
you can add another column to sub_task to make it into a key=>pair
then you can have as many dynamic fields as you want
 
right but how would i deal with different field types.. some details are boolean. some are int... some are text. so much goes into one post... thats where i keep breaking down.
 
7:10 AM
@dov would you store everything as a string? even ints and booleans?
 
7:26 AM
it depends how strict my values are, but usually there should be a problem
if u want to get very specific you can create an additional column that stores the type as a string and after you select the items from the DB cast them to the type you want
 

  last day (22 days later) »