Commit 3cfc55be authored by Fjen Undso's avatar Fjen Undso
Browse files

AnswerController: fix deletion of questionanswers

parent 02bacc6d
package controllers;
import java.util.ArrayList;
import java.util.List;
import models.QuestionAnswer;
......@@ -38,10 +39,11 @@ public class QuestionController extends Controller {
QuestionAnswer answer = Json.fromJson(json, QuestionAnswer.class);
if (!answer.owner.isEmpty()) {
// Delete old answer(s) from same owner
List<QuestionAnswer> oldAnswers = QuestionAnswer
.findFromOwner(answer.owner);
List<QuestionAnswer> oldAnswers = new ArrayList<QuestionAnswer>(session.questionAnswers);
for (QuestionAnswer qa : oldAnswers) {
qa.delete();
if (qa.owner.equals(answer.owner)) {
session.deleteAnswer(qa);
}
}
QuestionAnswer inserted = new QuestionAnswer(session, answer.owner,
......
......@@ -93,6 +93,11 @@ public class Session extends Model {
v.delete();
}
public void deleteAnswer(QuestionAnswer q) {
this.questionAnswers.remove(q);
q.delete();
}
public void addVote(Vote v) {
this.votes.add(v);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment