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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:29:51+00:00 2026-06-13T07:29:51+00:00

Assume the following model. Note the self-referencing relationship parent. class Widget(object): __tablename__ = ‘widgets’

  • 0

Assume the following model. Note the self-referencing relationship “parent”.

class Widget(object):
    __tablename__ = 'widgets'

    id = Column(Integer, primary_key=True)
    name = Column(String(100), nullable=False)
    parent_id = Column(Integer, ForeignKey('widgets.id'), nullable=True)
    parent = relationship("Widget", remote_side=[id])

I am attempting to formulate a query which will allow me to sort by “parent.name”. Specifying joins on the query doesn’t seem to have any affect on the SQL that is generated and executed.

I would be more specific about what I’ve tried thus far, but the thing is, I’ve thrashed all day on this and have pretty much exhausted the available documentation.

Any WAGs on what I should try?

  • 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-13T07:29:51+00:00Added an answer on June 13, 2026 at 7:29 am

    Take a look at the SA docs for self-referencing structures – in particular look at the declaration of Node just before the self-referential section begins.

    I’m not an expert on these hierarchical setups (they can get a little dicey) but it looks like you have set up your relationship opposite of the examples in the docs. That is not to say you are doing it wrong, but rather that the Node/Parent/Children example in the docs seems to map to what you’re trying to do. You should be able to set up your Widget in the same manner as the Node example, get the parent into your query, and then do the sort.

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

Sidebar

Related Questions

Lets assume I had the following Model class A(Models.model): def __init__(self,data): B(a=self,data=data).save() class B(Models.model):
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
Let's assume that we the following ndb model: class MyModel(ndb.Model): x = ndb.StringProperty() y
Assume the following: models.py class Entry(models.Model): title = models.CharField(max_length=50) slug = models.CharField(max_length=50, unique=True) body
Assume I have a Django model with the following fields: class Gizmo(models.Model): date_created =
Lets assume following classes definition: public class A { public final static String SOME_VALUE;
Assume the following: we have class B, which is a private class nested inside
I have the following Model class: package com.swaranga.model; public final class Book { private
Assume the following problem context: 1) In our application, we have a business object

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.