• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated almost 15 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

rails plugin that allows has_many :through to go through other has_many :throughs

NOTE: rails 2.3 users might want to try the experimental rails-2.3 branch¶ ↑

nested_has_many_through¶ ↑

A fantastic patch/plugin has been floating around for a while:

obrie made the original ticket and Matt Westcott released the first version of the plugin, under the MIT license. Many others have contributed, see the trac ticket for details.

Here is a refactored version (I didn’t write the original), suitable for edge/2.0-stable with a bunch of acceptance specs. I’m concentrating on plugin usage, once it becomes stable, and well enough speced/understood, then it’s time to pester rails-core.

Why republish this on github?¶ ↑

  • The previous implementations are very poorly speced/tested, so it’s pretty hard to refactor and understand this complicated bit of sql-fu, especially when you’re aiming at a moving target (edge)

  • the lastest patches don’t apply on edge

  • github - let’s collab to make this better and get a patch accepted, fork away!

Help out¶ ↑

I’m releasing ‘early and often’ in the hope that people will use it and find bugs/problems. Report them at ianwhite.lighthouseapp.com, or fork and pull request, yada yada.

History¶ ↑

Here’s the original description:

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).

Contributors¶ ↑

Get in touch if you should be on this list

Show me the money!¶ ↑

Here’s some models from the specs:

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

What does it run on?¶ ↑

Currently the master branch is running on 2.1, and 2.2 stable branches

Recent changes have made master incompatible with rails 2.0, if you want to use this with rails 2.0, then use the rails-2.0 branch.

If you want to run the CI suite, then check out garlic_example.rb (The CI suite is being cooked with garlic - git://github.com/ianwhite/garlic)

More Repositories

1

pickle

Easy model creation/reference in cucumber - optionally leveraging your factories/blueprints
Ruby
510
star
2

orm_adapter

Provides a single point of entry for using basic features of ruby ORMs
Ruby
194
star
3

resources_controller

resources_controller rails plugin: rc makes RESTful controllers fun
Ruby
79
star
4

truncate_html

rails helper that works just like truncate, but it respects, and produces well formed html
Ruby
63
star
5

garlic

garlic is a set of commands/rake tasks to help with CI across multiple rails/dependency versions
Ruby
34
star
6

inherit_views

rails plugin that enables inheritance of views along a controller class heirachy
Ruby
29
star
7

wac

Wolfram|Alpha client
Ruby
21
star
8

response_for

response for lets you decorate your actions respond_to blocks
Ruby
16
star
9

webrat_extra_steps

generator that parses your existing webrat steps to create some extra ones
Ruby
10
star
10

matewatch

Simple time tracking for textmate users
9
star
11

response_for_rc

Set of resourceful actions written in the response_for style for resources_controller
Ruby
9
star
12

git_friendly_dumper

Rails plugin that creates a dump directory with one file per record - much friendlier for git
Ruby
5
star
13

rc

resources_controller rewrite
Ruby
4
star
14

rspec-dev

Resources for rspec developers/contributors
Ruby
3
star
15

clag

Clag - not in active development - use machinist or factory_girl
Ruby
3
star
16

subit

Simple regexp based text substitution parser, with support for multiple rulesets, and in-place replacement
Ruby
3
star
17

clock_time

Adds Time.tomorrow, Time.yesterday, and instance methods like time.at_2am, time.at_0200
Ruby
3
star
18

handbrake-batch-convert.rb

Simple ruby script to batch convert using handbrake's cli
Ruby
2
star
19

dotfiles

My dotfiles
Shell
2
star
20

visit

Simple ruby visitor
1
star