Forum: Ruby on Rails Compound model names

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F10c5ded4c3f1dffe043cad7d0b9db47?d=identicon&s=25 Carlos Paramio (carlosparamio)
on 2007-01-24 12:49
(Received via mailing list)

I've a question about the use of compound names with my models
(separate models into modules).

I'm developing a big application for which my main models has a lot of
other referenced models via foreign keys, to reach a 3FN database

I know that it's possible to use something like Blog::Post as a model
name, and then put each model file into a subfolder. So I could create
a module called, for example, Blog, and then put there all the
submodels that are specific for the Blog module. This way I will have
a better organization of my project, instead of having a lot of files
at app/models. With Rails 1.2, it is necessary to add each subdir to
the load_path array on the configuration file, but this is ok.

Am I able to use the same model name in different modules? I mean, to
have for example two models called Post, one on a Blog module and the
other on the News module. How will relationships work then? Because if
I use has_many :posts on referenced models, how can Rails know that
I'm referring one Post model or the other? And the same for
map.resources macro on routes.rb. Is this possible, or I must use
different model names?

Thanks a lot!
Carlos Paramio
1e2c6a3f0bb018e0243ac4865c6e7431?d=identicon&s=25 Kevin Skoglund (Guest)
on 2007-01-25 16:50
(Received via mailing list)

I'm wondering about all the ins-and-outs of nesting models too.  Let me
know if you find an answer.

Is there anyone out there doing this who has already sorted through all
the pitfalls?  It would be great to have a Wiki page with details.

This topic is locked and can not be replied to.