Module: ActsAsTaggableOn::Taggable::Related::InstanceMethods
- Defined in:
- lib/acts_as_taggable_on/acts_as_taggable_on/related.rb
Instance Method Summary collapse
- #matching_contexts_for(search_context, result_context, klass, options = {}) ⇒ Object
- #related_tags_for(context, klass, options = {}) ⇒ Object
Instance Method Details
#matching_contexts_for(search_context, result_context, klass, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/acts_as_taggable_on/acts_as_taggable_on/related.rb', line 40 def matching_contexts_for(search_context, result_context, klass, = {}) = (search_context).collect { |t| t.name } exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(klass) : "#{klass.table_name}.#{klass.primary_key}" klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.id) AS count", :from => "#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}", :conditions => ["#{exclude_self} #{klass.table_name}.id = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.id AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?) AND #{ActsAsTaggableOn::Tagging.table_name}.context = ?", , result_context], :group => group_columns, :order => "count DESC" }.update()) end |
#related_tags_for(context, klass, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/acts_as_taggable_on/acts_as_taggable_on/related.rb', line 54 def (context, klass, = {}) = (context).collect { |t| t.name } exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(klass) : "#{klass.table_name}.#{klass.primary_key}" klass.scoped({ :select => "#{klass.table_name}.*, COUNT(#{ActsAsTaggableOn::Tag.table_name}.id) AS count", :from => "#{klass.table_name}, #{ActsAsTaggableOn::Tag.table_name}, #{ActsAsTaggableOn::Tagging.table_name}", :conditions => ["#{exclude_self} #{klass.table_name}.id = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.id AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?)", ], :group => group_columns, :order => "count DESC" }.update()) end |