On Dec 15, 2007, at 1:24 AM, Dave L. wrote:
class Avatar < ActiveRecord::Base
Users Table: id, screen_name, email, password, gender
class User < ActiveRecord::Base
You put those two in plural, right?
The problem you are facing comes from the fact that there’s no link
between admirers and avatars, yet you want to join them.
This in turn is consequence of what seems a not yet rounded model: to
admire and being admired is a relationship between users. That’s a
hands_and_belongs_to_many linking users to users, you need to link
them both ways.
The admirer’s table would have as columns: “admirer_id”, “admired_id”,
and NO column “id” (create_table :admirers, :id => false do |t| …).
In the User model you have
has_and_belongs_to_many :admirers, …, :join_table => ‘admirers’
has_and_belongs_to_many :admireds, …, :join_table => ‘admirers’
Check the API for the options in the ellipsis, Google for “self-
referential has_and_belongs_to_many” as well.
Then you have a link from users to avatars going through admirers,
is a collection of users, and they have avatars.