sql - Named scopes with inheritance in Rails 3 mapping to wrong table -


I am trying to use inheritance from a class that contains the named area:

 < Code> class one & lt; ActiveRecord :: Base area: useful_second, lambda {| Value1, value2. Where (: value1 = & gt; value1 ,: value2 = & gt; value2) end-end square b & lt; A set_ table_name "b" end   

is facing the problem that the name of the table in the SQL query still refers to the table of class A:

  A useful_scape ("alpha", "beta"). To_sql = & gt; "SELECT \" a \ "WHERE \" a \ ". \" Value1 \ "= 'alpha' and \" a \ ". \" Value2 \ "= 'beta'" b. Useful_scape ("alpha", "beta"). To_sql = & gt; "SELECT \" b \ ". * FROM \" b \ "ou \" a \ ". \" Value1 \ "= 'alpha' and \" a \ ". \" Value2 \ "= 'beta'"   

Note that the table names in the Zare statement now refer to A. I am modifying the current gem with various dependencies on class A scope, so I need to maintain the current syntax.

I have tried the following:

      • Lambda for table name Using the parameter, it breaks the syntax for other details, which gave only the current 2 properties.
      • Using an abstract class to define the scope The table name has only one binding, but using the class name of the abstract class.
      • Using the defined radius in a module and having the same name as the table name have occurred.

        Is there any way that I can scope for evaluation in each heritage classroom, so that it does not clearly map the original classes table?

        I ended up using an anonymous scope to solve this problem. The code looks like this:

          def self.useful_scope (value1, value2) scoped (: conditions => {value1 = & gt; value1 ,: value2 = & gt; value2 })   

        It now evaluates properly in both parent and heritage classes, and maintains the desired behavior of a scope.

Comments