fix has_many relationships in map & mapping models for rails 4

This commit is contained in:
Devin Howard 2015-09-10 22:48:35 +08:00 committed by Connor Turland
parent 8bf2eb31f3
commit 32311e3610
2 changed files with 5 additions and 5 deletions

View file

@ -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 => {

View file

@ -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"