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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:25:06+00:00 2026-05-26T07:25:06+00:00

I have a mapper on a table and I want to define a column_property

  • 0

I have a mapper on a table and I want to define a column_property which should select True or False whether the entity has some propertie or not:

mapper( Person, persons_table, properties = {
    'administrator': column_property( 
        select( 
            [True if roles_table.c.is_admin or roles_table.c.id == 1 else False],
            roles_table.c.id == persons_table.c.role_id
        ).label( 'administrator' )
        )
} )

Is this something I can do? I’m more interested in this part: [True if roles_table.c.is_admin or roles_table.c.id == 1 else False], which lets me set a value to the column based on the condition.

  • 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-26T07:25:07+00:00Added an answer on May 26, 2026 at 7:25 am

    Your SELECT-expression is actually a Python expression:

    select([True if roles_table.c.is_admin or roles_table.c.id == 1 else False],
           roles_table.c.id == persons_table.c.role_id)
    

    sqlalchemy.select() will see this as:

    select([True], some_expression_object)
    

    since the column object roles_table.c.is_admin will evaluate to True in Boolean context. I don’t know from the top of my head how SQLAlchemy will interpret this, but it will surely not work as you intended.

    You will have to rewrite this expression so that it will correspond to plain SQL, using sqlalchemy.sql.expression.case() instead of if ... else ...:

    column_property(
        select([case([(roles_table.c.is_admin, 1),
                      (roles_table.c.id == 1, 1)], else_=0)],
               roles_table.c.id == persons_table.c.role_id))
    

    In your case, however, there might be a much simpler solution. Person and Role seem to have a N:1 relation (one person has exactly one role). I assume there is a orm.relationship Person.role to get a person’s role.

    Why don’t you just add a plain Python property:

    class Person:
        # ...
    
        @property
        def administrator(self):
            return self.role and (self.role.is_admin or self.role.id == 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Hibernate Mapping, which has to be mapped using the Table
I have written one function in User Mapper class userExist($username) which return true if
I have this mapper defined: mapper(Resource, resource_table, properties = {'type' : relation(ResourceType,lazy = False),
We have a DB table that is mapped into a hibernate entity. So far
I have .MAP file which is created from SAS XML mapper. As the name
I access a a postgres table using SQLAlchemy. I want a query to have
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
So I have the following situation. I have a class DataTypes which has the
I have this piece of code for (element <- table.find; Right(info) = exceptionManager(mapper.getInfoFromDbObject(element))) yield
I have two LINQ table objects calls Orders and ImportedOrders which have exact the

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.