From 5313a125dbf8281172b19721024f160b0c21fedf Mon Sep 17 00:00:00 2001 From: Marcela Ribeiro de Oliveira <mro15@inf.ufpr.br> Date: Tue, 20 Mar 2018 08:16:17 -0300 Subject: [PATCH] add function to update edutional stages in learning objects put --- app/models/concerns/stageable.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/concerns/stageable.rb b/app/models/concerns/stageable.rb index f6acd144..11c76968 100644 --- a/app/models/concerns/stageable.rb +++ b/app/models/concerns/stageable.rb @@ -45,4 +45,11 @@ module Stageable StageRelation.where(educational_stage: educational_stage, stageable: self).destroy_all end end + + def update_educational_stages(ids: []) + stageable = self + old_ids = stageable.educational_stages.map {|es| es.id } + add_educational_stages(ids: ids - old_ids) + remove_educational_stages(ids: old_ids - ids) + end end -- GitLab