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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:55:12+00:00 2026-05-14T00:55:12+00:00

I have 3 models sites, user_favorites and users. Relevant relationships: class Site < ActiveRecord::Base

  • 0

I have 3 models

sites, user_favorites and users. Relevant relationships:

class Site < ActiveRecord::Base
  has_many :users, :through => :user_favorites

class UserFavorite < ActiveRecord::Base
  belongs_to :user, :counter_cache => true
  belongs_to :site
end

class User < ActiveRecord:Base
  has_many :user_favorites
  has_many :sites, :through => :user_favorites

All of that works just fine. I’d like to add a new attribute to the Site model to indicate which user created it.

I don’t believe this constitutes a has_and_belongs_to_many scenario. A site has many users through user_favorites but I want it to belong to a single user reflecting the owner/creator.

I’m wondering what the ORM best practice is for this. SQL wise I’d just use different joins depending on what I was trying to query with a created_by FK in Site. Sorry if I’m missing something basic here.

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-14T00:55:12+00:00Added an answer on May 14, 2026 at 12:55 am
    class Site < ActiveRecord::Base
      belongs_to :creator, :class_name => 'User'
      # ...
    end
    

    should be sufficient. Right? You can have multiple relationships between the same models, but you will find it extremely beneficial for organizational purposes to explicitly name them when such is the case.

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

Sidebar

Related Questions

I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have the following model set up: class UserProfile(models.Model): Additional attributes for users. url
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I have two models, Article and Post that both inherit from a base model
I have a models A and B , that are like this: class A(models.Model):
good day guys! in project, among others, have models: class Category(models.Model): name = models.CharField(max_length
I guess I have been using the Web Site model ever since .NET 2.0
I have my own game engine using C++ and OpenGL, but I have models
I'm working on a blog application in Django. Naturally, I have models set up

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.