2012-10-26 10:04:52 +00:00
|
|
|
class Mapping < ActiveRecord::Base
|
|
|
|
|
2015-10-02 08:04:30 +00:00
|
|
|
scope :topicmapping, -> { where(mappable_type: :Topic) }
|
|
|
|
scope :synapsemapping, -> { where(mappable_type: :Synapse) }
|
|
|
|
|
|
|
|
belongs_to :mappable, polymorphic: true
|
2016-01-26 10:42:24 +00:00
|
|
|
belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true
|
2014-08-12 22:14:04 +00:00
|
|
|
belongs_to :user
|
2016-01-26 09:58:33 +00:00
|
|
|
|
2016-02-21 09:25:39 +00:00
|
|
|
validates :xloc, presence: true,
|
|
|
|
unless: Proc.new { |m| m.mappable_type == 'Synapse' }
|
|
|
|
validates :yloc, presence: true,
|
|
|
|
unless: Proc.new { |m| m.mappable_type == 'Synapse' }
|
2016-01-26 09:58:33 +00:00
|
|
|
validates :map, presence: true
|
|
|
|
validates :mappable, presence: true
|
2014-08-12 16:01:01 +00:00
|
|
|
|
|
|
|
def user_name
|
|
|
|
self.user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_image
|
|
|
|
self.user.image.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json(options={})
|
|
|
|
super(:methods =>[:user_name, :user_image])
|
|
|
|
end
|
2013-04-26 04:07:29 +00:00
|
|
|
|
2012-10-26 10:04:52 +00:00
|
|
|
end
|