Frage

Ich habe zwei Modelle:

class Employee < ActiveRecord::Base
  has_many :projects
end

class Project < ActiveRecord::Base
  acts_as_taggable_on :skills, :roles
end

Ich möchte Mitarbeiter finden, die Tags mit ihren Projekten verbunden. Die Geokit-Schienen-Plugin unterstützt ein ähnliches Konzept, mit seinem ‚: durch‘. Beziehung

Im Idealfall würde ich in der Lage sein:

  • angeben, welche Tags (das heißt Fähigkeiten, Rollen) würde in den Bedingungen aufgenommen werden
  • , um die Mitarbeiter durch die Gesamtzahl der Projekte mit passenden Tags
  • Lage sein, die matching-Markierungszähler für jeden Mitarbeiter den Zugriff für die Zwecke einer Tag-Wolke Gebäude

Alle Gedanken geschätzt würde.

War es hilfreich?

Lösung

I'm not sure the acts-as-taggable-on has support for what you looking for directly. However, you might be able to get at what you want knowing that the acts_as_taggable_on method adds two has_many relationships to your Project model. For example, to find employees where the project's skills has some tags you can write

Employee.all(:joins => {:projects => :taggings}, :conditions => ['taggings.context = ? and taggings.tag_id in (?)', 'skills', [4, 8, 15, 16, 23, 42])

Of course that requires knowing the tag ids you are interested in, instead if you have the tag names then

Employee.all(:joins => {:projects => :base_tags}, :conditions => ['taggings.context = ? and tags.name in (?)', 'skills', ['skill_a', 'skill_b', 'skill_c'])

You might be able to expand that to do the different counts you are looking for as well.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top