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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:48:56+00:00 2026-05-23T07:48:56+00:00

sqlautocode – has issues with many-to-many relations sqlsoup – doesn’t support relations elixir –

  • 0

sqlautocode – has issues with many-to-many relations

sqlsoup – doesn’t support relations

elixir – it’s note auto-generate

Is there something else I could try?

  • 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-23T07:48:57+00:00Added an answer on May 23, 2026 at 7:48 am

    Well I went through that, tried on Northwind database and it looks promising. Although, I had to add relationship field to be able to follow database relations.

    Let’s consider that I don’t know relations between tables at the moment of starting the application so I need is a way to generate automatically.

    import unittest
    
    from sqlalchemy import *
    from sqlalchemy.orm import create_session
    from sqlalchemy.ext.declarative import declarative_base
    from datetime import datetime
    from sqlalchemy.orm import contains_eager, joinedload
    from sqlalchemy.orm import relationship
    
    #Create and engine and get the metadata
    Base = declarative_base()
    engine = create_engine('mssql://user:pass@Northwind', echo=True)
    metadata = MetaData(bind=engine)
    
    
    #Reflect each database table we need to use, using metadata
    class Customer(Base):
        __table__ = Table('Customers', metadata, autoload=True)
        orders = relationship("Order", backref="customer")
    
    class Shipper(Base):
        __table__ = Table('Shippers', metadata, autoload=True)
        orders = relationship("Order", backref="shipper")
    
    class Employee(Base):
        __table__ = Table('Employees', metadata, autoload=True)
    #    orders = relationship("Order", backref="employee")
        territories = relationship('Territory', secondary=Table('Employeeterritories', metadata, autoload=True))
    
    class Territory(Base):
        __table__ = Table('Territories', metadata, autoload=True)
        region = relationship('Region', backref='territories')
    
    class Region(Base):
        __table__ = Table('Region', metadata, autoload=True)
    
    
    class Order(Base):
        __table__ = Table('Orders', metadata, autoload=True)
        products = relationship('Product', secondary=Table('Order Details', metadata, autoload=True))
        employee = relationship('Employee', backref='orders')
    
    class Product(Base):
        __table__ = Table('Products', metadata, autoload=True)
        supplier = relationship('Supplier', backref='products')
        category = relationship('Category', backref='products') 
    
    class Supplier(Base):
        __table__ = Table('Suppliers', metadata, autoload=True)
    
    class Category(Base):
        __table__ = Table('Categories', metadata, autoload=True)
    
    
    class Test(unittest.TestCase):
    
        def setUp(self):
            #Create a session to use the tables    
            self.session = create_session(bind=engine)        
    
        def tearDown(self):
            self.session.close()
    
        def test_withJoins(self):
            q = self.session.query(Customer)
            q = q.join(Order)
            q = q.join(Shipper)
            q = q.filter(Customer.CustomerID =='ALFKI')
            q = q.filter(Order.OrderID=='10643')
            q = q.filter(Shipper.ShipperID=='1')
            q = q.options(contains_eager(Customer.orders, Order.shipper))
            res = q.all()
            cus = res[0]
            ord = cus.orders[0]
            shi = ord.shipper
            self.assertEqual(shi.Phone, '(503) 555-9831')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used sqlautocode to generate a model.py for an existing MySQL database and here's

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.