database connection in database.yml all the code for this are simple
ActiveRecord models. Is this the best direction for this?
I agree. Plugins are perfect for grouping together sets of model
The other issue I started to notice was that I should probably use some
sort of namespaces to prevent class conflicts. I started prefixing all
the models, currently 10 models in 10 files, with "Legacy::", but that
broke all the associations between these models. Of which, there are a
lot. Is there a better way to handle this too?
Yes, in your ActiveRecord associations specify ":class_name",
something like this:
class Foo < ActiveRecord::Base
has_many :bar, :class_name => 'Legacy::Bar', :foreign_key =>
This is only necessary for models that aren't part of the namespace:
all the "Legacy::" models can associate with each other without any
As on last bonus, as all these models use a custom database connection
is it best to just add that connection to the database.yml file, or
(can) should I put that connection information somewhere else so it is
better associated with the plugin itself?
I don't know if this would work best for you, but one approach would
be to make a parent class for all your other models. Set the database
connection in that parent class.
One caveat: if your ActiveRecord associations are across models in
different databases you might have problems, because of the way Rails
does joins etc. behind the scenes. So if you encounter problems you
can do your relationships manually instead of using ActiveRecord's
associations: you can write methods in your models that find
associated records, etc.