Skip to content

Easily use named scopes to scope associations in a very DRY manner.

License

Notifications You must be signed in to change notification settings

kristopher/scoped-associations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScopedAssociations

Use your named scopes to add conditions to associations! Keep your code DRY and allows eager loading of scoped associations.

Currently this only works for has_many associations, and probably only on Rails 2.2.

Example

class User < ActiveRecord::Base
  has_many :published_posts, :scope => :published
  has_many :published_and_approved_posts, :scope => [:published, :approved]
end

class Post < ActiveRecord::Base
  named_scope :published, :conditions => { :published => true }
  named_scope :approved, :conditions => { :approved => true }
end

Install

As a Rails plugin:

./script/plugin install git://github.com/kristopher/scoped-associations.git

Prefer gems? Add this to your environment.rb and run the following command.

config.gem 'kristopher-scoped-associations', :lib => 'scoped-associations', :source => 'http://gems.github.com'

$ rake gems:install
Homepage

github.com/kristopher/scoped-associations

License

Copyright © 2008 Kristopher Chambers <[email protected]> and Elijah Miller <[email protected]>, released under the MIT license

About

Easily use named scopes to scope associations in a very DRY manner.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages