Forum: Ruby on Rails acts_as_paranoid, aliasing and nested scopes in Rails 1.1

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dave (Guest)
on 2006-05-11 14:13
I have a real problem with the acts_as_paranoid plugin. The aliasing of
find and so the nested scope does not seem to work at all, when
combining it with similar plugins.

The description:
I made a copy of 'acts_as_paranoid' in the plugin directory, renamed it
to 'acts_as_very_new'(just a nonsense plugin for testing), and
simplified the code (original code of acts_as_paranoid can be found
here:
http://svn.techno-weenie.net/projects/plugins/acts...

#--------------------------------------------------------------BEGIN
 module VeryNew
   #...
   module ClassMethods
     def acts_as_very_new
       unless is_very_new?
         class << self
           alias_method :find_with_old,  :find
         end
       end
       include InstanceMethods
     end
     #...
   end

   module InstanceMethods #:nodoc:
     #...

     module ClassMethods
       def find(*args)
         with_very_new_scope { find_with_old(*args) }
       end

       protected
         def with_very_new_scope(&block)
           with_scope({:find => {:conditions =>
["#{table_name}.updated_at > ?", (Time.new - 3.days)]} }, :merge,
&block)
         end
     end

   end
 end
#--------------------------------------------------------------END

As you can see, there's no change in structure, it's the same as the
original 'acts_as_paranoid' only with a different find-condition. Next I
added following code to a model:

#--------------------------------------------------------------BEGIN
class Book < ActiveRecord::Base
  acts_as_paranoid
  acts_as_very_new
  #...
end
#--------------------------------------------------------------END

In a controller I did the following calls:

 Book.find(:all)
 # SQL: SELECT * FROM books WHERE ((books.updated_at > '2006-05-08
11:38:33') AND (books.deleted_at IS NULL))

 Book.find_with_old(:all)
 # SQL: SELECT * FROM books WHERE (books.deleted_at IS NULL)

 Book.find_with_deleted(:all)
 # SQL: SELECT * FROM books

Isn't is strange? Shouldn't "Book.find_with_deleted(:all)" generate a
"WHERE (books.updated_at > '2006-05-08 11:38:33')" condition? The
problem seems to be in aliasing of find. When I switch the call order of
"acts_as_paranoid" and "acts_as_very_new" in the model, I get:

 Book.find(:all)
 # SQL: SELECT * FROM books WHERE ((books.updated_at > '2006-05-08
11:38:33') AND (books.deleted_at IS NULL))

 Book.find_with_old(:all)
 # SQL: SELECT * FROM books

 Book.find_with_deleted(:all)
 # SQL: SELECT * FROM books WHERE (books.updated_at > '2006-05-08
11:38:33')


Has anyone an idea how to fix it?
Thanks in advance,
Dave
This topic is locked and can not be replied to.