has_many_polymorphs icon indicating copy to clipboard operation
has_many_polymorphs copied to clipboard

polymorphic associations over different Namespaces - not possible?!

Open mugwump opened this issue 16 years ago • 5 comments
trafficstars

I have the following situation:

class Housing::Kennel < ActiveRecord::Base has_many_polymorphs :guests, :from => [:dogs,:cats,_birds] end

class GuestKennel < ActiveRecord::Base belongs_to :kennel belongs_to :guest, :polymorphic => true end

class Pets::Dog < ActiveRecord::Base end

Which I cannot get to run: (ActiveRecord::Associations::PolymorphicError: Could not find a valid class for :guests_kennels (tried GuestsKennel). If it's namespaced, be sure to specify it as :"guests/guests_kennels" instead.) - the error-message varies, depending in which module Kennel, GuestsKennel, Dog are put.

In the end, putting all three classes in one module and adding this module with :namespace => :housingandpets solves this issue.

Is there a way to specifiy the module for all three particpiants (Kennel, GuestsKennel, Dog) independently from each other and put them into different modules?!

(and thx for hmp anyway, works great!)

mugwump avatar Apr 30 '09 16:04 mugwump

Is anybody looking into this anyway?!

mugwump avatar May 12 '09 04:05 mugwump

no. best bet is to make a failing test and fix it yourself; this project is in patch-accepting-mode only :-/

ghost avatar Aug 05 '09 21:08 ghost

sorry, just wondering if this was the right place to ask these kind of questions. Meanwhile I just stopped trying to put my models into modules: That produces all kinds of nasty side-efffects, not only with has_many_polymorphs - so basically, this works as designed :)

mugwump avatar Aug 06 '09 06:08 mugwump

I've got a patch that fixes this (more shortly).

stepheneb avatar Aug 14 '09 17:08 stepheneb

The namespaced_models branch in my fork supports loading names-spaced models in has_many_polymorphs autoload.rb.

Here's the commit where it was added:

http://github.com/stepheneb/has_many_polymorphs/commit/b563f4d65faabc494c8dcef3d3d5c34d2bc2af20

stepheneb avatar Aug 14 '09 21:08 stepheneb