This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Wed May 20 09:44:04 -0700 2009 | |
| |
MIT-LICENSE | Tue May 19 08:33:45 -0700 2009 | |
| |
README.rdoc | Wed May 20 09:44:04 -0700 2009 | |
| |
Rakefile | ||
| |
VERSION | ||
| |
init.rb | Tue May 19 08:33:45 -0700 2009 | |
| |
install.rb | Tue May 19 08:33:45 -0700 2009 | |
| |
lib/ | Wed May 20 09:33:57 -0700 2009 | |
| |
mighty_associations.gemspec | ||
| |
test/ | Wed May 20 09:33:57 -0700 2009 | |
| |
uninstall.rb | Tue May 19 08:33:45 -0700 2009 |
README.rdoc
Mighty Associations
Extends many of your associations for free. Given the following models:
class Task < ActiveRecord::Base
belongs_to :project
end
class Project < ActiveRecord::Base
has_many :tasks
belongs_to :company
named_scope :five_letters, :conditions => "LENGTH(name) = 5"
end
class Company < ActiveRecord::Base
has_many :projects
has_many :tasks, :through => :project
named_scope :five_letters, :conditions => "LENGTH(name) = 5"
end
You can:
Get all projects belonging to a company:
Company.projects
Get all projects belonging to a company with a 5-letter name:
Company.five_letters.projects
It also works with has_many :through associations:
Company.tasks
Company.five_letters.tasks
Return value is a scope, so you can still chain it:
Company.five_letters.projects.find_by_name("Wadus")
The same applies for belongs_to associations, for example you can get the companies with a five-letter project:
Project.five_letter.companies
Copyright © 2009 BeBanjo, released under the MIT license








