This repository has been archived by the owner on Oct 9, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add short description and example to readme
- Loading branch information
Showing
1 changed file
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
RelationalScope | ||
=============== | ||
|
||
Introduction goes here. | ||
This plugin makes it possible to filter a specific model using the | ||
named_scope's of one of its relations. This prevents making duplicate | ||
named_scopes in multiple models. | ||
|
||
|
||
Example | ||
======= | ||
|
||
Example goes here. | ||
class Post < ActiveRecord::Base | ||
belongs_to :author | ||
|
||
has_relational_scope :author, :prefix => 'a' | ||
end | ||
|
||
class User < ActiveRecord::Base | ||
named_scope :admins, :conditions => {:admin => true} | ||
end | ||
|
||
In your Controller you can go: | ||
|
||
@posts = Post.a_admins | ||
|
||
This will fetch all and only posts where the author is an admin. | ||
|
||
Without the :prefix option this would be called as Post.author_admins | ||
|
||
|
||
Copyright (c) 2009 Zachery Hostens, released under the MIT license |