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