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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:19:51+00:00 2026-06-18T08:19:51+00:00

Hello i have trouble with logic. In my app users can create Posts and

  • 0

Hello i have trouble with logic. In my app users can create Posts and add them to favourites. The problem is in assiciations on Posts and Users. When User creates Post user_id is applied to posts table. How can i make associations when other user or this one add Post to favourite.

  • 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-18T08:19:52+00:00Added an answer on June 18, 2026 at 8:19 am

    You need to create another table that will join a post and user. You can call that table favorites with 2 columns: post_id and user_id

    class Favorite < ActiveRecord::Base
      belongs_to :post
      belongs_to :user
    end
    
    class User < ActiveRecord::Base
      has_many :posts
      has_many :favorites
      has_many :favorite_posts, through: :favorites, source: :post
    end
    
    class Post < ActiveRecord::Base
      belongs_to :user
      has_many :favorites
      has_many :favorited_by_users, through: :favorites, source: :user
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document with a dynamic UI--users can add rows to an existing
Hello dearest community. I have trouble in the last two days, that I can't
Hello I have been having trouble with this for a while now. I have
Hello I'm trying to learn ruby blocks. But I have a trouble to get
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello i have 2 arrays and and i want to put them in a
Hello my fellow developers, I have some trouble polishing my UI. I've made a
I'm having some trouble figuring this out. I have the following CSV string hello
Hello i have trouble with parsing a pdf when the iterator reaches page 11
Hello I have trouble finding a string within a file which consists of the

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.