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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:27:22+00:00 2026-06-03T09:27:22+00:00

I have a model Zone , a model Entity and a model Transit .

  • 0

I have a model Zone, a model Entity and a model Transit. Transit is minimally defined as:

class Entity(db.Model):
    __tablename__ = 'entities'
    id = db.Column(db.Integer, primary_key=True)
    contained_by = db.Column(db.Integer, db.ForeignKey('entities.id'))
    contains = db.relationship('Entity', backref='container')
    discriminator = db.Column('type', db.String(50))
    __mapper_args__ = {'polymorphic_on': discriminator}

class Zone(Entity):
    __mapper_args__ = {'polymorphic_identity': 'zones'}
    routes = db.relationship('Transit')
    (stuff goes here)

class Transit(db.Model):
    __tablename__ = "transits"
    start = db.Column(db.Integer, db.ForeignKey('zones.id'))
    end = db.Column(db.Integer, db.ForeignKey('zones.id'))

Zone also has a couple of bits about distance and how defensible it is, but that is irrelevant for this.

  • First off, due to the fact that Zone is subclassed from Entity using single-table inheritance can I reference zones.id?
  • Secondly, will the Zone.routes property merge Transit.start and Transit.end?
  • 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-03T09:27:23+00:00Added an answer on June 3, 2026 at 9:27 am
    1. no, you need to use the table name, which in your case (Single-table inheritance) is entities
    2. no, these will not be merged. You can create two relationships, and have a (hybrid) property which would combine both, but this will only be for reading purposes, as when you would like to modify this property (for example, add Transits), you would still need to specify both sides (start and end).
    3. I am not sure I understand the question here

    update-1: as requested in comment, Concrete-Table inheritance code below:

    class Zone(Entity):
        __mapper_args__ = {'polymorphic_identity': 'zones'}
        __tablename__ = "zones"
        id          = Column(Integer, ForeignKey('entities.id'), primary_key=True)
        @property
        def transits(self):
            return self.transits_from_here + self.transits_to_here
    
    class Transit(Base):
        __tablename__ = "transits"
        id          = Column(Integer, primary_key=True)
        start = Column(Integer, ForeignKey('zones.id'))
        end = Column(Integer, ForeignKey('zones.id'))
    
        s_zone = relationship(Zone, primaryjoin=(start==Zone.id), backref="transits_from_here")
        e_zone = relationship(Zone, primaryjoin=(end==Zone.id), backref="transits_to_here")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
Lets say I have model inheritance set up in the way defined below. class
I have a meeting model with a start time column: class Meeting(mode.Model): name =
I have a model: class Zone(models.Model): name = models.CharField(max_length=128) users = models.ManyToManyField(User, related_name='zones', null=True,
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have a domain data model which returns a class such as the following:
I have the following model and methods: class UserPrice < ActiveRecord::Base attr_accessible :price, :purchase_date,
I have the following Mongoid model... class Event include Mongoid::Document include Mongoid::Timestamps::Created include Mongoid::Timestamps::Updated
I have a tree of Zone objects: class Zone { protected Zone $parent; public

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.