Question:
How can I tell ActiveRecord to not include the namespace of the association class while storing/querying the association type column?
Current state of things:
Consider the following class definitions:
class PageTemplateA < ActiveRecord::Base
has_many :type_a_pages, :as => :pageable, :class_name => 'TypeAPage', :inverse_of => :pageable
end
##### The following class is implemented through STI.
class TypeAPage < Page
belongs_to :pageable, :class_name => 'PageTemplateA', :inverse_of => :type_a_page
end
class Page < ActiveRecord::Base
belongs_to :pageable, :polymorphic => true
end
To summarize:
TypeAPage
is implemented through STI in the database table,pages
.TypeAPage
is associated withPageTemplateA
through a polymorphic association (pages.pageable_type
isPageTemplateA
when associated withPageTemplateA
)
The change I want to make:
I want to move all the above models into a new namespace, say, PagesEngine
, so my definition for PageTemplateA
looks like:
module PagesEngine
class PageTemplateA < ActiveRecord::Base
has_many :type_a_pages, :as => :pageable, :class_name => 'TypeAPage', :inverse_of => :pageable
end
end
This works fine, except that ActiveRecord infers the pageable_type
for TypeAPage
to be PagesEngine::PageTemplateA
.
How can I tell ActiveRecord to not include the namespace, and resolve pageable_type
to PageTemplateA
instead of PagesEngine::PageTemplateA
?