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

  • Home
  • SEARCH
  • 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 3676406
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:05:43+00:00 2026-05-19T03:05:43+00:00

I am setting up a simple has_many through relationship. I was wondering if there

  • 0

I am setting up a simple has_many through relationship. I was wondering if there are any best practices I should consider when setting up the foreign key relationships.

The application is designed to allow users to create items and ads, where a listing model is used to connect items with ads (the listing model also has timestamps and an order field).

The main question I have is: which models should belong_to the user model? I was thinking that the simplest solution is to have listing belong_to user. That way I can use the has_many through relationship to figure out which items and which ads belong_to each user.

However, it occurred to me that this could leave some holes depending on what work-flows I want to make possible. For example, what if a user wants to create a bunch of items before creating an ad which has those items? What if a user creates an ad before having created any items?

Based on the above, I was thinking that maybe I should just make ads and items belong to user. If I do that, is there any obvious reason to also make listing belong_to user? I was going to do that, but somehow it just looked redundant to me.

This seems like a pretty typical situation to encounter in a rails app, so I was hoping somebody with experience has been here and might be able to share some insight.

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-19T03:05:44+00:00Added an answer on May 19, 2026 at 3:05 am

    I’m trying to understand what you have:

    User
    Ad
    Item
    Listing

    Where Listing appears to be some kind of join model that relates an Item to being in an Ad.

    I don’t see much of a wrong way to do this. I suppose the most normalized way of doing this would be to just have an Item belong_to a User, and get the Listings and Ads through that. But you’d be paying a price there too, both in having to write annoying code and having to perform multiple joins to get your Ads.

    The opposite extreme is just to have everything belong_to the user. You have an extra column in 2 of your models, but then you also have much simpler relationships. You also wouldn’t have to worry about what workflows your users are allowed when designing your schema.

    Even if you mess up and leave out user_id fields in your models, it isn’t terribly hard to add those fields later using migrations.

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

Sidebar

Related Questions

What would be the best approach for implementing Tasks with a KEY that operate
All, This question probably has a very simple answer - something I'm overlooking. But
Hello I am creating a simple form to enter employee information. An employee has
Like many other developers out there, I've created iPhone projects that use a UITabBarController
I'm utilizing the magic of jQuery.ajax( settings ) . However, I'm wondering if anyone
I am running a Perl server with 10 threads. They never get destroyed until
Ok, I have no idea why this is happening. I'm made an Item class
I am working on a very large Rails application. We initially did not use
Bit of a jquery Newbie here, so go easy. Basically I'm trying to plug
I'm still in need of help. I have website settings that I want to

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.