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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:31:50+00:00 2026-06-03T07:31:50+00:00

I have a model Thing which can be subclassed by several types of Thing

  • 0

I have a model Thing which can be subclassed by several types of Thing like PointyThing and TastyThing. I have a second model, Instance that is related one-to-many to Things (one Instance may be of the type of a single Thing but there will be many Instances of a given Thing). Instances are then related to a Player (each instance has one Player but a player has many Instances) with a backref so that a Player can call it’s .inventory property to see what it owns.

All well and good, but I also have a model Place. I would like for Places to own Instances too in the same way that a Player owns an instance.

Would it be best to create an Owner model that is linked against with the Instance model and then subclassed to get Players and Places or some hereto unknown method within SQLAlchemy that I don’t yet know of?

  • 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-03T07:31:51+00:00Added an answer on June 3, 2026 at 7:31 am

    I think the best solution you are asking for depends on many factors.

    Technically, if I look at your example in isolation, this solution looks like a pretty descent hack which avoids creating another relationship table. And if you will never query with polymorphic support, this could fly just fine. However it would still be a hack. Imagine that later you extend your Player model with few more sub-classes, and you might start using polymorphic queries, and you will always have to ask yourself "how will it impact my hack"?. And even if everything still would work fine (right now I cannot come up with example which would break your logic), you would still need to be careful.
    But lets look what is the benefit of this hack? We save on one relationship table, but in fact you introduce another table for your Owner model (I assume Concrete Table Inheritance), so what is the gain really?

    On the other hand, I am wondering if your Instance table should not in fact be a ternary relationship? I assume that each instance of the Thing is stored in some Place and might belong to a Player, so it might just be one table that looks like:

    Instance[
        ID primary_key, 
        Thing_ID (FK) NOT NULL, 
        Place_ID (FK) NOT NULL, 
        Person_ID (FK) NULL
    ]
    

    Note that Person_ID is nullable, as I assume the instance of the Thing might not belong to anyone until assigned. But it could be that it is always NOT NULL in your case.

    Hope this helps. Would be good to learn which way you decide to go and why.

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

Sidebar

Related Questions

For instance, let's say I have a User model. Users have things like logins,
I have something for which I can't find the right syntax: /Views/Shared/EditorTemplates/Component.cshtml @model Website.Models.Component
I have model Foo which has field bar. The bar field should be unique,
I have model Article it has field title with some text that may contain
I have model like this: scope :search_posts, lambda { |query| mega_posts.where( title LIKE ?
I have a QTreeView to which I set a subclassed DomModel:QAbstractItemModel. Each item is
I have a model like this class Parent < ActiveRecord::Base :has_many :kids end class
For example I have data model like this Entity: Store Entity: Inventory Entity:Product Attribute:
I have a generic model framework with a few entities and relationships that I'd
I have a model, Post , which has a field called is_viewed , which

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.