Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 761861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:53:20+00:00 2026-05-14T15:53:20+00:00

Basically, I have a users model in my rails app, and a fanship model,

  • 0

Basically, I have a users model in my rails app, and a fanship model, to facilitate the ability for users to become ‘fans’ of each other.

In my user model, I have:

has_many :fanships
has_many :fanofs, :through => :fanships

In my fanship model, I have:

belongs_to :user
belongs_to :fanof, :class_name => "User", :foreign_key => "fanof_id"

My fanship table basically consists of :id, :user_id and :fanof_id. This all works fine, and I can see what users a specific user is a fan of like:

<% @user.fanofs.each do |fan| %>
    #things
<% end %>

My question is, how can I get a list of the users that are a fan of this specific user?

I’d like it if I could just have something like @user.fans, but if that isn’t possible what is the most efficient way of going about this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:53:20+00:00Added an answer on May 14, 2026 at 3:53 pm

    Add in User model:

    has_many :my_fanclubs, :class_name => 'Fanship', :foreign_key => 'fanof_id'
    has_many :fans, :through => :my_fanclubs, :source => :user, :class_name => 'User'
    

    (not tested)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to rails and building a small test app on rails3 (beta4). I
I'm building a Rails app that needs to connect to a custom TCP data
I'm doing a little rails app for a prototype. I started off using a
i have a simple record system in rails, it has customers , appointments and
I have recently designed a web application that I would like to write in
I thought that there should have been a simple solution to this, given that
I've created a locally attached SQL Server 2008 Express for an ASP.NET MVC application
I asked a question earlier , and got an excellent response, but, being a
Hey guys I was wondering if anyone could help me with an issue im

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.