goncalossilva/rails3_acts_as_paranoid — pull request #93 by gvieira (2013-01-19 13:58:08+00:00)
Title: Remove table name from default scope sql queries

Hi there,

I'm using `acts_as_paranoid` in a situation where I have an inheritance through MTI. I defined only the root model as `acts_as_paranoid`.

So, the problem is default_scope. The gem define (using Arel, in default use):

`default_scope { where('tablename'.'delete_at' IS NULL) }`.

When I try to fetch a subclass model, I got an error telling me `tablename` does not exists. And it is true. It doesn't. After a little debugging, I've found out it was because of the `default_scope` that was getting executed only when the root class was loaded (it uses the root class context).

I could get along with this changing the `default_scope` to something like this:

`default_scope :condition => { :deleted_at => nil }

This way, the condition gets executed every time somebody asks for a relation. It works in default case, but it doesn't where deleted_at is a string. I really tried something to make it, but I couldn't find a way.

Well, the only solution I came up into was changing the string condition, creating it manually (without Areal), so I could reproduce what's were built but without the table name. I know it can be dangerous in multi tabled queries, but I had no other option.

Please let me know if you have any other solution for my situation. I would be happy to make it better.

Regards,
Vieira