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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:35:41+00:00 2026-05-29T22:35:41+00:00

With the following tables and mappings class A: def __init__(self): self.id = None self.b_ids

  • 0

With the following tables and mappings

class A:
    def __init__(self):
        self.id = None
        self.b_ids = {}
        self.b_s = {}

class B:
    def __init__ (self):
        self.id = None
        self.a_id = None
        self.a = None

a = Table('t_a', meta,
    Column('id',Integer, autoincrement=True, primary_key=True),
    )

b = Table('t_b', meta,
    Column('id',Integer, autoincrement=True, primary_key=True),
    Column('a_id', Integer, ForeignKey('t_a.id')),
    )

mapper(A, a)
mapper(B, b, properties={'a' : relationship(A, backref="b_s")})

When I load ‘A’ I can get the related ‘B’ objects in the ‘b_s’ property. But What I want is a list of ids of related Bs in the A.b_ids property. Is there a way to do this?

I tried :

mapper(A, a, properties={'b_ids' : 
                         column_property(select(
                                                [b.c.id], 
                                                a.c.id==b.c.a_id))
                         })

But its giving error: ‘ProgrammingError: (ProgrammingError) more than one row returned by a subquery used as an expression’

  • 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-29T22:35:42+00:00Added an answer on May 29, 2026 at 10:35 pm

    column_property() is used to add another column to the SELECT statement, such as this:

    SELECT a.x, a.y, (SELECT b.id FROM b where a.id=b.a_id) AS b_id FROM a
    

    In SQL, that’s a subquery in the columns clause of the SELECT statement, and it needs to return exactly one row/column for each row – in SQLAlchemy we call this a “scalar select”.

    In this case you’re looking for a list, so that’s not embedded into the main columns clause there. That’s why the database returns an error for that. Your mapping already has a list of “b ids” on it, in the form of “b_s”. You just want to extract the “id” from that, and this can be done pretty easily with the association proxy:

    from sqlalchemy.ext.associationproxy import association_proxy
    
    class A(object):
        # ... other things
        b_ids = association_proxy('b_s', 'id')
    

    When you access “a.b_ids”, it will look at each entry within “b_s” and extract the “id” attribute, returning a collection that’s compatible with the type of collection of “b_s”, which in this case is a Python list.

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

Sidebar

Related Questions

I have the following mapping for my table in MySql: <class name=Tag, namespace table=tags
Imagine the following tables: create table boxes( id int, name text, ...); create table
I have two tables (tbArea, tbPost) that relate to the following classes. class Area
I have the following classes and fluent mappings: public class A { public virtual
I have the following tables: create table Users( Id uniqueidentifier primary key, InfoId uniqueidentifier
I have a DB with the following tables Users Roles UserInRoles (Bridge table for
I have the following tables/views Users (View) -> UserId -> Name Roles (Table) ->
I have a hibernate mapping as follows: <hibernate-mapping> <class name=kochman.elie.data.types.InvoiceTVO table=INVOICE> <id name=id column=ID>
Is there a way to preform the following mappings (using database-first approach) : Tables:
I have the following mappings: public class SecurityMap : ClassMap<Security> { public SecurityMap() {

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.