I have the following models.
# app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name => "Link", :as => :from, :dependent => :destroy end # app/models/link.rb class Link < ActiveRecord::Base belongs_to :from, :polymorphic => true belongs_to :object_value, :polymorphic => true end
The problem is that when I do the following, from_type is not the domain namespace prefix for the model, for example.
Domain::DomainObject.all(:include=> :links_from )
This calls the following SELECT:
SELECT `links`.* FROM `links` WHERE (`links`.`from_id` IN (5,6,12,13,18,24,25,27,29,30,31,32,34,35,39) and `links`.`from_type` = 'DomainObject')
The request should be:
SELECT `links`.* FROM `links` WHERE (`links`.`from_id` IN (5,6,12,13,18,24,25,27,29,30,31,32,34,35,39) and `links`.`from_type` = 'Domain::DomainObject')
because Rails automatically saves a model with a namespace.
I saw several recommendations on Rails sites on how to do this:
belongs_to :from, :polymorphic => true, :class_name => "Domain::DomainObject"
However, this does not work either.
So, is there a better way to do this? Or is it not supported?