mam takie dwie encje
public function up()
{
Schema::create('configurations', function (Blueprint $table) {
$table->increments('id');
$table->date('date_from');
$table->integer('race_id');
$table->timestamps();
});
}
w modelu mam
public function parameters()
{
return $this->hasMany('App\Models\Parameter');
}
oraz listę parametrów przypisanych do danej konfiguracji
public function up()
{
Schema::create('parameters', function (Blueprint $table) {
$table->increments('id');
$table->integer('configuration_id');
$table->tinyInteger('day');
$table->decimal('water', 8, 3);
$table->smallInteger('feed');
$table->smallInteger('weight');
$table->decimal('downs');
$table->timestamps();
pytania z założeniami:
- Potrzebuję wyciągnąć zsumowaną pod względem ( water, feed, weight, downs ) listę parametrów należące do configuracji o id in (tutaj różnie może być od jednego id po kilka)
$configuration = Configuration::whereIn('race_id', [1, 2])->get();
- Z konwencji, jak kodować
return $this->hasMany('App\Models\Parameter');
//czy
return $this->hasMany(Parameter::class');