Admirers Table : id, user_id, admirer_id (the admirer_id is the one
that needs to be displayed by creating an avatar object with the
corresponding user_id)
class Admirer < ActiveRecord::Base
belongs_to :user
end
Avatars Table: id, user_id, content_type, thumbnail, size, width,
height (uses attachment_fu)
class Avatar < ActiveRecord::Base
belongs_to :user
end
Users Table: id, screen_name, email, password, gender
class User < ActiveRecord::Base
has_one :photo
has_many :avatar
has_many :admirer
You put those two in plural, right?
end
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, because
user.admirers
is a collection of users, and they have avatars.
-- fxn