Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from UbikTransmedia/gist:fba247056b4ef2fdc1a3
Last active January 6, 2016 10:15
Show Gist options
  • Save universal/e7adcb465a70338b3906 to your computer and use it in GitHub Desktop.
Save universal/e7adcb465a70338b3906 to your computer and use it in GitHub Desktop.
--- ERR
uninitialized constant User::Aimed
--- Facing cols
id, aimer_id, aimed_id, aimed_kind (will be deprecated), aimed_type, created_at, updated_at
--- Facing.rb
class Facing < ActiveRecord::Base
#Relation model dealing with users pointing to users
#belongs_to :aimer, class_name: "User"
belongs_to :aimer, :polymorphic => true
#belongs_to :aimed, class_name: "User"
belongs_to :aimed, :polymorphic => true
end
class User
#People the user is facing (objects: records & user/clan objects)
has_many :active_facings, as: :aimer, class_name: "Facing", foreign_key: "aimer_id", dependent: :destroy
has_many :aimeds, through: :active_facings, source_type: "Aimed"
#People who is facing the user (objects: records & user/clan objects)
#old: has_many :passive_facings, class_name: "Facing", foreign_key: "aimed_id", dependent: :destroy
has_many :passive_facings, as: :aimed, class_name: "Facing", foreign_key: "aimed_id", dependent: :destroy
has_many :aimings, through: :passive_facings, source_type: "Aimed"
def aims_to?(other)
# if other.class.name == 'User'
aimeds.include?(other) <----------------------------- IT BREAKS HERE!!
# elsif other.class.name == 'Clan'
# active_facings
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment