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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:14:35+00:00 2026-05-25T17:14:35+00:00

I am using SQLAlchemy but not in the declarative manner, I essentially am trying

  • 0

I am using SQLAlchemy but not in the declarative manner, I essentially am trying to populate a database using data being fed by a SOAP web service (dynamic classes).

What I am having trouble with is creating the mappings between the different parts of the object, this is being made more difficult by the fact that the tables are on MySQL’s MyISAM tables which don’t have foreign key support.

import sqlalchemy

dbE = sqlalchemy.create_engine('create string')
dbM = sqlalchemy.MetaData()
dbM.bind = dbE

class Invoice(object):
    pass

class LineItem(object):
    pass

InvoiceTbl = sqlalchemy.Table('Invoices', dbM, autoload = True)
LineItemTbl = sqlalchemy.Table('Invoices_Items', dbM, autoload = True)

LineItemMapper = orm.mapper(InvoiceLineItemTbl, InvoiceLineItemTbl)
InvoiceMapper = orm.mapper(Invoice, InvoiceTbl)

sm = orm.sessionmaker(bind = dbE, autoflush = True, autocommit = False, 
                      expire_on_commit = True)
session = orm.scoped_session(sm)

Using the above I can query for the different parts of an invoice separately with the following, the objects get populated with the columns present in the matching table:

invoiceData = session.query(Invoice).filter(Invoice.InvoiceNumber.like('12345'))
invoiceItems = session.query(LineItem).filter(LineItem.InvoiceNumber.like('12345'))

What I want to do is make the LineItems as part of the Invoice:

orm.mapper(Invoice, InvoiceTbl properties={
    'LineItems' : orm.relation(LineItem),
    })

But this comes back with an error about it doesn’t know about the relation between the two objects / tables (understandable given that no foreign keys exist). I’ve been trying different parameters (primaryjoin, backref, etc) but I have not been successful thus far.

Any help would be appreciated, I understand this may not be the best way to do this but this particular script is data driven and needs to be somewhat dynamic in the event the SOAP service changes.

edit:
shahjapan’s suggestion of primaryjoin argument helps but I am now getting an error “Could not determine relationship direction for primaryjoin condition” so I assume we are on the right track, just not there yet.

  • 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-25T17:14:36+00:00Added an answer on May 25, 2026 at 5:14 pm

    Just give foreign key in the child and it will work authomaticaly.

    LineItme

    LineItemTbl = sqlalchemy.Table('Invoices_Items', dbM,
        Column(InvoiceNumber, ForeignKey('InvoiceTbl.InvoiceNumber),
        autoload = True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to map an object to a database using SQLAlchemy but have
I am developing a Python web app using sqlalchemy to communicate with mysql database.
I'm creating the web app using Pyramid-1.2.1 with SQLAlchemy as database backend. Now I
I am using SQLAlchemy with declarative base and Python 2.6.7 to insert data in
I'm using an ORM (SQLAlchemy, but my question is quite implementation-agnostic) to model a
I am trying the following in PyQt4, using SQLAlchemy as the backend for a
I'm using Pyramid and SQLAlchemy, but the following simplified code: u = u\u201C m
I am using a relational database via SQLAlchemy. I want to spawn a job
I'm using Pylons (a python framework) to serve a simple web application, but it
I am using SqlAlchemy, a python ORM library. And I used to access database

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.