Reference two columns on another table or reference the id?

Posted 5 months ago by midwestdev

I have a parent called formula_items that will have many ingredient, and it has a parent that will have many formulas I don't want to have to add ingredients each time so I want to include a dropdown that list the ingredients and when you create the formula item it will reference the ingredients. (doing it this way in case later the ingredients change in some fashion, it will just cascade down to all the formulas and formula items.

I am probably over complicating in my head a simple one to one relationship as I haven't slept in 20 hours, but this is my UP migration.

public function up()
{
    Schema::create('formula_items', function (Blueprint $table) {
        $table->increments('id');
    $table->unsignedInteger('formulas_id');
        $table->foreign('ingredients_id')->references('id')->on('Ingredients');
        $table->double('quantity_needed');
        $table->timestamps();
    });
}

I am pretty certain this is right, but if I am wrong I would appreciate some advice on how I can rethink this?

Please sign in or create an account to participate in this conversation.