From 748991147eb9a17c6121e2f236764dd8b3f00321 Mon Sep 17 00:00:00 2001
From: Ruben Young On <r.d.youngon@student.tudelft.nl>
Date: Sat, 18 May 2019 14:45:51 +0200
Subject: [PATCH] Added hybrid property to problem, removed direct relation
 between mc_option and problem, changed API

---
 zesje/api/mult_choice.py | 2 +-
 zesje/database.py        | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/zesje/api/mult_choice.py b/zesje/api/mult_choice.py
index edb09182..b2f2f4a6 100644
--- a/zesje/api/mult_choice.py
+++ b/zesje/api/mult_choice.py
@@ -88,7 +88,7 @@ class MultipleChoice(Resource):
         if not mc_entry:
             return dict(status=404, message=f"Multiple choice question with id {id} does not exist"), 404
 
-        set_mc_data(mc_entry, name, x, y, mc_type, problem_id, feedback_id, label)
+        set_mc_data(mc_entry, name, x, y, mc_type, feedback_id, label)
         db.session.commit()
 
         return dict(status=200, message=f'Multiple choice question with id {id} updated'), 200
diff --git a/zesje/database.py b/zesje/database.py
index 16f53b27..157eb9b4 100644
--- a/zesje/database.py
+++ b/zesje/database.py
@@ -8,6 +8,7 @@ from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, Foreign
 from flask_sqlalchemy.model import BindMetaMixin, Model
 from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
 from sqlalchemy.orm.session import object_session
+from sqlalchemy.ext.hybrid import hybrid_property
 
 
 # Class for NOT automatically determining table names
@@ -98,9 +99,12 @@ class Problem(db.Model):
     exam_id = Column(Integer, ForeignKey('exam.id'), nullable=False)
     feedback_options = db.relationship('FeedbackOption', backref='problem', order_by='FeedbackOption.id', lazy=True)
     solutions = db.relationship('Solution', backref='problem', lazy=True)
-    mc_options = db.relationship('MultipleChoiceOption', backref='problem', lazy=True)
     widget = db.relationship('ProblemWidget', backref='problem', uselist=False, lazy=True)
 
+    @hybrid_property
+    def mc_options(self):
+        return [mc_option for mc_option in self.feedback_options]
+
 
 class FeedbackOption(db.Model):
     """feedback option"""
-- 
GitLab