evan / has_many_polymorphs

An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/
Academic Free License v3.0
201 stars 57 forks source link

polymorphic associations over different Namespaces - not possible?! #2

Open mugwump opened 15 years ago

mugwump commented 15 years ago

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 commented 15 years ago

Is anybody looking into this anyway?!

ghost commented 15 years ago

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

mugwump commented 15 years ago

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 :)

stepheneb commented 15 years ago

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

stepheneb commented 15 years ago

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