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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:36:20+00:00 2026-06-07T17:36:20+00:00

I have two tabels user and friends, The user tabel looks like this: [id,

  • 0

I have two tabels user and friends,

The user tabel looks like this:

[id, name, image, location, highschool_name, highschool_year, college_name, college_year, graduteschool_name, graduate_year ]

And the friend tabel looks like this:

[id, uid, name, image, higschool_name, college_name, graduateschool_name, user_id]

I would like to group Users friends by eduaction:

  • Group users friends by highschool_name
  • Group users friends by college_name
  • Group users friends by graduateschool_name

Like this photoshop mockup I made:

enter image description here

I am dev in Rails 3 and would like to use active record to do this, any tip or ideas are welcome.

  • 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-07T17:36:21+00:00Added an answer on June 7, 2026 at 5:36 pm

    You should create higschool, college and graduateschool models and use relations to users.
    And friends data should be on user model.

    So you should have

    User
      has_many :friendships
      has_many :friends, :through => :friendships
      has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
      has_many :inverse_friends, :through => :inverse_friendships, :source => :user
      belongs_to :higschool
      belongs_to :college
      belongs_to :graduateschool
    
    Friendship
      belongs_to :user
      belongs_to :friend, :class_name => "User"
    
    Higschool
      has_many :users
    
    College
      has_many :users
    
    Graduateschool
      has_many :users
    

    So, now I think you can do something like.

    @higschool_friends = Hash[]
    current_user.friends.group_by(&:higschool) do | higschool, friends |
      @higschool_friends[higschool] = friends
    end
    
    @college_friends = Hash[]
    current_user.friends.group_by(&:college) do | college, friends |
      @college_friends[college] = friends
    end
    
    @graduateschool_friends = Hash[]
    current_user.friends.group_by(&:graduateschool) do | graduateschool, friends |
      @graduateschool_friends[graduateschool] = friends
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables like this: TABLE user( id CHAR(100) text TEXT ) TABLE
Need help figuring this out. I have two tables user ---- name skills (comma
I have two tables. The first table is Requests and it looks like this
I have two tables user table user_id | name | 1 | peter |
I have two tables user and log. I would like to join the user
I have two tables. I query like this: SELECT * FROM ( Select requester_name,receiver_name
Say, I have two tables like these: Table group Table user +----+-----------+ +----+----------+------+----------+ |
I have two tables User id name Result id user_id score created_at Every hour
I have two tables user and location user has id(primary) and location fields/columns location
I have two tables: User and User2Friend . I need to get user's friends.

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.