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 9319491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:23:55+00:00 2026-06-19T03:23:55+00:00

I am trying to save a person’s Facebook friends into my database. I want

  • 0

I am trying to save a person’s Facebook friends into my database. I want to store the Facebook users in a table and then store their friendships in another table. The friendships would have the integer of the FacebookUser that requested the friendship and the integer of the friend, both of which are foreign keys to the facebook_users table. However I keep getting this message when I try to link the a user’s facebook friends with friendships.

Error

ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not find the source association(s) :friend or :friends in model Friendship. Try 'has_many :friends, :through => :friendships, :source 
=> <name>'. Is it one of :FacebookUser or :FacebookFriend?

friendship.rb

class Friendship < ActiveRecord::Base
  attr_accessible :facebook_user_id, :facebook_friend_id

  belongs_to :FacebookUser
  belongs_to :FacebookFriend, :class_name => :FacebookUser
end

facebook_user.rb

class FacebookUser < ActiveRecord::Base
  attr_accessible :first_name, :gender, :last_name

  has_many :friendships, :foreign_key => :facebook_user_id
  has_many :friends, :through => :friendships, :source => :FacebookUser
end

Schema

create_table "facebook_users", :force => true do |t|
  t.string   "first_name"
  t.string   "last_name"
  t.string   "gender"
  t.datetime "created_at", :null => false
  t.datetime "updated_at", :null => false
end

create_table "friendships", :force => true do |t|
  t.integer "facebook_user_id"
  t.integer "facebook_friend_id"
end
  • 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-06-19T03:23:56+00:00Added an answer on June 19, 2026 at 3:23 am

    the convention Rails uses is to use associations as defined by the class name and the foreign key. if you’ve set up your tables like above, you should change your models to the following.

    class Friendship < ActiveRecord::Base
      attr_accessible :facebook_user_id, :facebook_friend_id
    
      belongs_to :facebook_user # implies a foreign key of facebook_user_id and class of FacebookUser
      belongs_to :facebook_friend, class_name: 'FacebookUser' #implies a foreign key of facebook_friend_id
    end
    
    class FacebookUser < ActiveRecord::Base
      attr_accessible :first_name, :gender, :last_name
    
      has_many :friendships
      has_many :friends, :through => :friendships, :source => :facebook_friend
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to save a row in my settings table, it works all fine
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to save some data into an array but unfortunately all the data
I'm trying to save a huge NSArray to a file and then retrieve it...
I'm trying to save the kABFirstNamePropert, kABLastNameProperty and kABAddressProperty all saved into an array
I am trying to create a vector of Person objects. However I really want
i am trying to save person along with his address. I have one to
So I am trying to save arrays into an NSDictionary on the fly. Let
Im trying to save a simple script in netbeans to htdocs, but i only
I'm trying to save a CUploadedFile object in local folder, I am using img

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.