Bi-directional HABTM relationships are easy in Rails, but when you need to do it on a single model, that's when it gets tricky. Here's one approach.
Here are a couple methods for dealing with uni-directional many-to-many associations in Rails.
Sometimes you need access to multiple database within a single rake task, for whatever reason. Here's how you do it.