Nested Objects - Design Question
Hello together,
(this is my first post) :-)
I have a database design question for laravel eloquent.
Right now I'm trying to make a nested database structure to detect times (f.e. 15 Mintues) for different services.
An example. I have the following tables:
ServiceType (id,name): Category 1, Category 2, Category 3
ServiceCategories (id,name,service_type_id): Repair (Category 1), Solder (Category 1), Disassemble (Category 2), Destroy (Category 3)
Services: (id, name, default_workload, service_category_id): Solder 1 (Solder): 15Min, Solder 2 (Solder) 30 Min, Solder 3 (Solder) 10 Min, Repair 1 (Repair) 10Min, Repair 2 (Repair) 20Min, Disassemble 1 (Disassemble) 40 Min, Destroy 1 (Destroy) 10 Min
So this structure works for now, the database looks like:
Services:
Schema::create('services', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('service_category_id')->unsigned()->index();
$table->string('name');
$table->time('default_workload');
$table->timestamps();
$table->foreign('service_category_id')->references('id')->on('service_categories')->onDelete('cascade');
});
ServiceCategories:
Schema::create('service_categories', function (Blueprint $table) {
$table->increments('id');
$table->integer('service_type_id')->unsigned()->index();
$table->string('name');
$table->timestamps();
$table->foreign('service_type_id')->references('id')->on('service_types')->onDelete('cascade');
});
ServiceTypes:
Schema::create('service_types', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Now I want to add the option to choose for another category. This is where my question starts. At all, the structure for my database should look like:
Category 1 -> Category 2 -> ServiceCategory - Service
The Category 2 could have following content:
Short, Middle, Long
As I choose short, middle, long .. the default_workload for the service changes. (f.e. + 15 Minute), additional minutes will be added to the default_workload.
Now I thought about different options to solve this problem:
- Put a table in between category 1 and service category. in this case i would multiply all my service categorys 3 times. Because I would need them for each Category 2 (short, middle, long). Which would not be optimal, because the ServiceCategories stay the same for a Category all the time. It does not depent on Category 2
- Link the Category 2 to a Service. This would be a good solution (so i thought). But after "almost" implementing this I realized it could be complicated in selecting a default_workload. In this case I would have to look for a default_workload or "if there is" a link to Category 2 a value from Category 2.
Right now I think I made a design failure and try to work around it. Maybe somebody can help me out?
Some ideas, experience on this?
Thank you so much!
Please or to participate in this conversation.