2012-10-26 06:04:52 -04:00
|
|
|
class Mapping < ActiveRecord::Base
|
|
|
|
|
2015-10-02 16:04:30 +08:00
|
|
|
scope :topicmapping, -> { where(mappable_type: :Topic) }
|
|
|
|
scope :synapsemapping, -> { where(mappable_type: :Synapse) }
|
|
|
|
|
|
|
|
belongs_to :mappable, polymorphic: true
|
2015-09-10 22:48:35 +08:00
|
|
|
|
2014-08-12 18:14:04 -04:00
|
|
|
belongs_to :map, :class_name => "Map", :foreign_key => "map_id"
|
2012-10-26 06:04:52 -04:00
|
|
|
|
2014-08-12 18:14:04 -04:00
|
|
|
belongs_to :user
|
2014-08-12 12:01:01 -04: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 00:07:29 -04:00
|
|
|
|
2012-10-26 06:04:52 -04:00
|
|
|
end
|