From dca3de3bc766175f49b56202246d3625c58fd763 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 17 Jan 2010 23:22:11 +0530 Subject: Make relations work as scopes --- activerecord/test/models/post.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/test/models') 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} } } } -- cgit v1.2.3