Hi. I'm hoping somebody can tell me that I've just gotten my syntax
wrong and I can in fact do what I want to do.
I've got a Group, and a Group has_many Campaigns.
Campaign has_and_belongs_to_many Users (and, naturally, vice versa).
So I've got a groups table, a campaigns table (that has a group_id), a
campaigns_users join table (with campaign_id and user_id), and a users
table (who basically is left not belonging to anyone).
My question is this -- starting from Group I want to reach through that
HABTM and point directly at the Users who belong to this Group. I've
successfully done it by writing my own finder_sql, or by just cheating
and collapsing all the camaign.users together. But I'm working on a
user interface for this and I'd like my list of users to behave just
like any other activerecord operation so that I can page through them,
sort arbitrarily on columns and so on exactly as if I'd originally just
had "Group has many Users".
I was hoping that this would work:
has_many :users, :through=>:campaigns
But it doesn't, all I ever get is
ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source
reflection macro :has_and_belongs_to_many for has_many :users, :through
=> :campaigns. Use :source to specify the source reflection.
However I don't understand what it wants in the :source option. It's
not like I mucked around with any class_names. (Well, technically this
is inheriting an old database so the actual table names are being
overridden, but I'm hoping that's not it! it's not as if I'm getting
bad SQL generated because an assumed table name does not exist).