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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:02:40+00:00 2026-05-13T08:02:40+00:00

I have three tables (users, articles, and tags) defined in SQLAlchemy and mapped with

  • 0

I have three tables (users, articles, and tags) defined in SQLAlchemy and mapped with orm.mapper(). As you can see below, I’m adding a property “author” to each article which ties that article to the user that created it.

orm.mapper(User, t_users)
orm.mapper(Tag, t_tags)
orm.mapper(Article, t_articles, properties={
    'author' : orm.relation(User),
    'tags' : orm.relation(Tag, secondary=t_tags_articles),
    })

I’m listing an index of articles, and each article will need to show its tags and its author. I’m trying to figure out the best way (minimal SQL queries, better performance) to retrieve the author and tags data.

If I do this:

results = Session.query(Article).all()

then I can pull the author and tags for each article in the index like this:

author = results[0].author
tags = results[0].tags

but this runs two new queries for each results[x] that I loop through (yikes). If I do this:

results = Session.query(Article, User).join('author').all()

then I can access the author data like this (because it’s joined in):

firstname = results[0].firstname

but trying to get a list of tags doesn’t work, and instead raises an AttributeError (‘rowTuple’ object has no attribute ‘tags’):

tags = results[0].tags

What am I doing wrong, and what’s the best way to access the data for this index?

  • 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-13T08:02:40+00:00Added an answer on May 13, 2026 at 8:02 am

    Considered eagerloading, as covered in Working with Related Objects?

    Your join is also funky. You’re mixing the ORM with the SQL-toolkit, so you’re getting row-objects and not mapped objects back. See Querying with Joins

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

Sidebar

Related Questions

I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator
I have three tables which are defined as: class User(Base): __tablename__ = 'users' id
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
Basicall I have three Tables Users Roles and USerRoles with Many to many Relationship.
In my database I have three tables: Users: UserID (Auto Numbering), UserName, UserPassword and
I have three database tables: users emails invitations Emails are linked to users by
Say I have three tables, a table of users, a table of around 500
I have users table. There are three other tables: developers, managers, testers. All of
I have three mysql tables, first holds information about articles (Article ID, author ID,
Imagine that we have a website where users can read articles, view photos, watch

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.