Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mugwump opened this issue Apr 30, 2009 · 5 comments
Open

Comments

@mugwump
Copy link

mugwump commented Apr 30, 2009

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
Copy link
Author

mugwump commented May 12, 2009

Is anybody looking into this anyway?!

@ghost
Copy link

ghost commented Aug 5, 2009

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

@mugwump
Copy link
Author

mugwump commented Aug 6, 2009

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
Copy link
Contributor

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

@stepheneb
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants