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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:47:05+00:00 2026-06-07T23:47:05+00:00

Been reading the documentation for SQLAlchemy and I cant my head around this. Consider

  • 0

Been reading the documentation for SQLAlchemy and I cant my head around this. Consider the following setup:

boardset_user_association_table = db.Table('boardset_user_association', 
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('boardset_id', db.Integer, db.ForeignKey('boardset.id'))
)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True)
    password = db.Column(db.String(30))
    boardSet = db.relationship('BoardSet', secondary=boardset_user_association_table, backref='user')

    def __repr__(self):
        return "<User('%s','%s')>" % (self.username, self.id)

class BoardSet(db.Model):
    __tablename__ = 'boardset'
    id = db.Column(db.Integer, primary_key=True)
    created = db.Column(db.DateTime)
    boards = db.relationship('Board', backref='boardset', lazy='dynamic')

    def __repr__(self):
        return "<BoardSet('%s','%s')>" % (self.id, self.created)

I get the collection of items from the User object but I fail performing any filtering etc on the actual data. I would like for example in some situations order the results from User.boardSet by value in field Created

  • 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-06-07T23:47:06+00:00Added an answer on June 7, 2026 at 11:47 pm

    Well, you could use lazy='dynamic' also for boardSet, in which case you will get a benefit of

    dynamic – the attribute will return a pre-configured Query object for
    all read operations, onto which further filtering operations can be
    applied before iterating the results.

    class User(...):
        ...
        boardSet = db.relationship('BoardSet', secondary=boardset_user_association_table, backref='user', lazy='dynamic')
    
    myuser = session.query(User).get(1)
    boardsets = myuser.boardSet.order_by(BoardSet.created)
    

    Of course, you can easily order the items also in memory after you loaded simply buy doing sorted(myuser.boardSet, key=lambda bs: bs.created)

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

Sidebar

Related Questions

I've been reading the documentation but I can't find a way to do this.
I've been reading the documentation which at a point says This dialog will request
I've been reading Twitter's documentation on this but I'm a bit confused because I'm
I have been reading Qt documentation and playing around with the qobject tree. I
I'm struggling to get my head round django forms.. I've been reading various documentation
I have been reading through the documentation on the JavaScriptMVC framework and it looks
hello im new to python and have been reading over the documentation and am
i've been reading through the linq to xml documentation in msdn and some other
What I have been able to grasp from reading the source and documentation from
I have been reading documentation describing class inheritance, abstract base classes and even python

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.