From a8cef723a24b1c5e216dc8891a3ff7319a458217 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 10 Sep 2015 22:48:35 +0800 Subject: [PATCH] fix has_many relationships in map & mapping models for rails 4 --- app/models/map.rb | 7 ++----- app/models/mapping.rb | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 3bf5a4a6..dffb9fae 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -2,11 +2,8 @@ class Map < ActiveRecord::Base belongs_to :user - has_many :topicmappings, :class_name => 'Mapping', :conditions => {:category => 'Topic'} - has_many :synapsemappings, :class_name => 'Mapping', :conditions => {:category => 'Synapse'} - - has_many :topics, :through => :topicmappings - has_many :synapses, :through => :synapsemappings + has_many :topics, -> { Mapping.topicmapping }, :through => :topicmappings + has_many :synapses, -> { Mapping.synapsemapping }, :through => :synapsemappings # This method associates the attribute ":image" with a file attachment has_attached_file :screenshot, :styles => { diff --git a/app/models/mapping.rb b/app/models/mapping.rb index dc50730c..9d6b4947 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,5 +1,8 @@ class Mapping < ActiveRecord::Base + scope :topicmapping, -> { where (category: :Topic) } + scope :synapsemapping, -> { where (category: :Synapse) } + belongs_to :topic, :class_name => "Topic", :foreign_key => "topic_id" belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id" belongs_to :map, :class_name => "Map", :foreign_key => "map_id"