Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created September 18, 2010 10:33
Show Gist options
  • Save bjeanes/585553 to your computer and use it in GitHub Desktop.
Save bjeanes/585553 to your computer and use it in GitHub Desktop.
# This is until there is a nested_has_many_through solution for Rails 3
# to let us do something like:
#
# has_many :interests, :through => :users, :select => "DISTINCT tags.*",
# :class_name => "ActsAsTaggableOn::Tag"
def interests
ActsAsTaggableOn::Tag.
select("DISTINCT tags.*").joins(:taggings).
where("taggings.context" => "interests").
where("taggings.taggable_type" => "User").
where("taggings.taggable_id" => user_ids).
order("tags.name")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment