Class: Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::Validations, PgSearch
Defined in:
lib/ecrire/app/models/tag.rb

Direct Known Subclasses

Admin::Tag

Defined Under Namespace

Classes: PostsAssociation, Validator

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/ecrire/app/models/tag.rb', line 39

def ==(other)
  self.class.table_name == other.class.table_name && self.id == other.id
end

#postsObject



43
44
45
46
47
48
49
# File 'lib/ecrire/app/models/tag.rb', line 43

def posts
  post_scope = ->(tag) { where '? = ANY (posts.tags)', tag.id }
  options = {}
  reflection = ActiveRecord::Reflection::HasManyReflection.new(:posts, post_scope, options, self.class)
  association = PostsAssociation.new(self, reflection)
  @posts ||= ActiveRecord::Associations::CollectionProxy.new(Post, association)
end