No release in over 3 years
Low commit activity in last 3 years
Traversing superpowers for your ActiveRecord associations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 4.0.0, >= 3.1.0
 Project Readme

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