dependent destroy models for topics/maps/synapses on mappings
This commit is contained in:
parent
bb29e0e724
commit
9e43cc2e96
6 changed files with 9 additions and 51 deletions
|
@ -218,15 +218,7 @@ class MapsController < ApplicationController
|
||||||
|
|
||||||
@map = Map.find(params[:id]).authorize_to_delete(@current)
|
@map = Map.find(params[:id]).authorize_to_delete(@current)
|
||||||
|
|
||||||
if @map
|
@map.delete if @map
|
||||||
@mappings = @map.mappings
|
|
||||||
|
|
||||||
@mappings.each do |mapping|
|
|
||||||
mapping.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
@map.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json {
|
format.json {
|
||||||
|
|
|
@ -50,15 +50,7 @@ class SynapsesController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@synapse = Synapse.find(params[:id]).authorize_to_delete(@current)
|
@synapse = Synapse.find(params[:id]).authorize_to_delete(@current)
|
||||||
|
@synapse.delete if @synapse
|
||||||
if @synapse
|
|
||||||
@synapse.mappings.each do |m|
|
|
||||||
m.map.touch(:updated_at)
|
|
||||||
m.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
@synapse.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
|
|
@ -200,33 +200,7 @@ class TopicsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@current = current_user
|
@current = current_user
|
||||||
@topic = Topic.find(params[:id]).authorize_to_delete(@current)
|
@topic = Topic.find(params[:id]).authorize_to_delete(@current)
|
||||||
|
@topic.delete if @topic
|
||||||
if @topic
|
|
||||||
@synapses = @topic.synapses
|
|
||||||
@mappings = @topic.mappings
|
|
||||||
|
|
||||||
@synapses.each do |synapse|
|
|
||||||
synapse.mappings.each do |m|
|
|
||||||
|
|
||||||
@map = m.map
|
|
||||||
@map.touch(:updated_at)
|
|
||||||
|
|
||||||
m.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
synapse.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
@mappings.each do |mapping|
|
|
||||||
|
|
||||||
@map = mapping.map
|
|
||||||
@map.touch(:updated_at)
|
|
||||||
|
|
||||||
mapping.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
@topic.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
|
|
@ -2,8 +2,8 @@ class Map < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping
|
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
|
||||||
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping
|
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
|
||||||
has_many :topics, through: :topicmappings
|
has_many :topics, through: :topicmappings
|
||||||
has_many :synapses, through: :synapsemappings
|
has_many :synapses, through: :synapsemappings
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Synapse < ActiveRecord::Base
|
||||||
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
|
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id"
|
||||||
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
|
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
|
||||||
|
|
||||||
has_many :mappings
|
has_many :mappings, dependent: :destroy
|
||||||
has_many :maps, :through => :mappings
|
has_many :maps, :through => :mappings
|
||||||
|
|
||||||
def user_name
|
def user_name
|
||||||
|
|
|
@ -3,12 +3,12 @@ class Topic < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id'
|
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy
|
||||||
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id'
|
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy
|
||||||
has_many :topics1, :through => :synapses2, :source => :topic1
|
has_many :topics1, :through => :synapses2, :source => :topic1
|
||||||
has_many :topics2, :through => :synapses1, :source => :topic2
|
has_many :topics2, :through => :synapses1, :source => :topic2
|
||||||
|
|
||||||
has_many :mappings
|
has_many :mappings, dependent: :destroy
|
||||||
has_many :maps, :through => :mappings
|
has_many :maps, :through => :mappings
|
||||||
|
|
||||||
# This method associates the attribute ":image" with a file attachment
|
# This method associates the attribute ":image" with a file attachment
|
||||||
|
|
Loading…
Reference in a new issue