Skip to content

Commit

Permalink
Merge pull request #862 from openmultiplechoice/levinuss/parent-deriv…
Browse files Browse the repository at this point in the history
…ed-session

Save parent session for derived sessions
  • Loading branch information
schu committed May 14, 2024
2 parents f836910 + 4f38128 commit 4af72ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function newFromIncorrect(Request $request, Session $session)
$newSession->name = $deck->name;
$newSession->current_question_id = $deck->questions()->first()->id;
$newSession->user_id = Auth::id();
$newSession->parent_session_id = $session->id;
$newSession->save();

return response()->json($newSession);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public function answerChoices()
{
return $this->hasMany(AnswerChoice::class);
}

public function parentSession()
{
return $this->belongsTo(Session::class, 'parent_session_id');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
public function up(): void
{
Schema::table('sessions', function (Blueprint $table) {
$table->bigInteger('parent_session_id')->unsigned()->nullable();
$table->foreign('parent_session_id')->references('id')->on('sessions');
});
}

public function down(): void
{
Schema::table('', function (Blueprint $table) {
//
});
}
};

0 comments on commit 4af72ae

Please sign in to comment.