No commit activity in last 3 years
No release in over 3 years
This plugin makes it possible to define has_many :through relationships that go through other has_many :through relationships, possibly through an arbitrarily deep hierarchy. This allows associations across any number of tables to be constructed, without having to resort to find_by_sql (which isn't a suitable solution if you need to do eager loading through :include as well).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
~> 2.5.0
>= 0

Runtime

>= 3.0.0
 Project Readme

NestedHasManyThrough¶ ↑

This gem makes it possible to define has_many :through relationships that go through other has_many :through relationships, possibly through an arbitrarily deep hierarchy. This allows associations across any number of tables to be constructed, without having to resort to find_by_sql (which isn’t a suitable solution if you need to do eager loading through :include as well).

NOTE: Rails 3.x supports only. Rails 2.3 users might want to try the original nested_has_many_through plugin

Intallation¶ ↑

Install the gem:

gem install nested_has_many_through
Add it to your gem file

gem “nested_has_many_through”

Usage¶ ↑

class Author < User
  has_many :posts
  has_many :categories, :through => :posts, :uniq => true
  has_many :similar_posts, :through => :categories, :source => :posts
  has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true
  has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true
  has_many :commenters, :through => :posts, :uniq => true
end

class Post < ActiveRecord::Base
  belongs_to :author
  belongs_to :category
  has_many :comments
  has_many :commenters, :through => :comments, :source => :user, :uniq => true
end

The first two has_manys of Author are plain vanilla, the last four are what this plugin enables

# has_many through a has_many :through
has_many :similar_posts, :through => :categories, :source => :posts

# doubly nested has_many :through
has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true

# whoah!
has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true

# has_many through a has_many :through in another model
has_many :commenters, :through => :posts, :uniq => true

Maintainers¶ ↑

Copyrights¶ ↑

This gem based on code nested_has_many_through plugin

MIT License. Copyright © 2008 Ian White - ian.w.white@gmail.com