Class: Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tag
show all
- Includes:
- ActiveModel::Validations, PgSearch
- Defined in:
- lib/ecrire/app/models/tag.rb
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
|
#posts ⇒ Object
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
|