Forum: Rails-core (closed, excessive spam) class_inheritable_accessor corner case

Posted by Frederick Cheung (Guest)
on 2008-06-13 19:16
(Received via mailing list)
Consider the following:

class Base
   class_inheritable_accessor :value
end
Base.value = SomeActiveRecordClass
class Concrete < Base; end

Reasonable enough. Concrete.value.find will die horribly, because
Concrete.value.table_name is the empty string.

I believe this is because in class_inheritable_accessor we dup the
values, in this case SomeActiveRecordClass/
  The duped class isn't assigned to a constant and so has no name (at
least on ruby 1.8.6), and since we derive table names from class names
we're boned. (unless SomeActiveRecordClass had already set its table
name).

Storing classes like this isn't really a great idea idea anyway
(because of class reloading in dev mode) but it seems the duping
classes like this isn't really necessary, and could lead to hard to
diagnose problems

Making it not dup classes seems to fix the problem, but I wondered if
someone who knows this corner of ActiveSupport could cast any extra
light?

Fred
This topic is locked and can not be replied to.