aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-17 23:22:11 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-17 23:22:11 +0530
commitdca3de3bc766175f49b56202246d3625c58fd763 (patch)
tree2f6ed2fed53a8fc57b6e716b59ee2c6ebaa6f40f /activerecord/test/models
parentf0cde5be541e1f3877a15fb5d39c87a487a14381 (diff)
downloadrails-dca3de3bc766175f49b56202246d3625c58fd763.tar.gz
rails-dca3de3bc766175f49b56202246d3625c58fd763.tar.bz2
rails-dca3de3bc766175f49b56202246d3625c58fd763.zip
Make relations work as scopes
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/post.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 662f75c39f..b5f9328139 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -1,7 +1,7 @@
class Post < ActiveRecord::Base
- named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'"
- named_scope :ranked_by_comments, :order => "comments_count DESC"
- named_scope :limit_by, lambda {|limit| {:limit => limit} }
+ named_scope :containing_the_letter_a, where("body LIKE '%a%'")
+ named_scope :ranked_by_comments, order("comments_count DESC")
+ named_scope :limit_by, lambda {|l| limit(l) }
named_scope :with_authors_at_address, lambda { |address| {
:conditions => [ 'authors.author_address_id = ?', address.id ],
:joins => 'JOIN authors ON authors.id = posts.author_id'
@@ -20,7 +20,7 @@ class Post < ActiveRecord::Base
has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
named_scope :with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} }
- named_scope :with_very_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'VerySpecialComment'} }
+ named_scope :with_very_special_comments, joins(:comments).where(:comments => {:type => 'VerySpecialComment'})
named_scope :with_post, lambda {|post_id|
{ :joins => :comments, :conditions => {:comments => {:post_id => post_id} } }
}