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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:59:42+00:00 2026-05-15T07:59:42+00:00

I have two models, users and themes, that I’m currently joining in a HABTM

  • 0

I have two models, users and themes, that I’m currently joining in a HABTM association in a themes_users table. Basically, after a user creates a new theme, it becomes available to other users to select for their own use.

However, only the original creator of the theme should have the ability to edit it. So, I need to have some other kind of association to handle that relationship, something like an created_by_id field in the theme.

In this way, the user model acts as two different roles: they can be an implementer of a theme AND/OR the owner of the theme. The implementer relationship is handled by the themes_users join table; the question is: What is the right way to handle this secondary association? Do I need to make users polymorphic and then make the created_by_id reference an “owner”? Or is there something easier?

Thanks so much for your help!

  • 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-15T07:59:42+00:00Added an answer on May 15, 2026 at 7:59 am

    I believe you should add the following association

    class User < ApplicationController
       # a user can create many themes
       has_many :themes_created, :foreign_key => :creator_id, :class_name => "Theme"
    end
    
    class Theme < ApplicationController
       # add a creator_id column in your themes table
       belongs_to :creator, :class_name => "User"
    end
    

    This way you can get all the themes created by some @user through

    @user.themes_created
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have two models- Users and Accounts. Each account can have at
I have two models, user and group. I also have a joining table groups_users.
I have two models that has a manytomany relationship with a 'through' table in
From a practical and best practices perspective, should rails models that have HABTM association
I have two models, Article and Post that both inherit from a base model
I have two models, Room and Image . Image is a generic model that
I have two models Users and Roles . I have setup a many to
I have two models, Users and Groups. Each group can have many users and
I have two models and a join table, User , Post and posts_users .
If I have two Models that have a manytomany relationship with a through model,

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.