title: Flask SQLAlchemy query with order_by returns error no such column
body: <p>Here is my models:</p>
  
  <pre><code>from flask import Flask
  from flask_sqlalchemy import SQLAlchemy
  
  
  app = Flask(__name__)
  db = SQLAlchemy(app)
  
  
  class Person(db.Model):
      __tablename__ = 'persons'
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(64), nullable=False, unique=True)
      pets = db.relationship('Pet', backref='owner', lazy='dynamic')
  
      def __init__(self, *args, **kwargs):
          super(Person, self).__init__(*args, **kwargs)
  
      def __repr__(self):
          return f'&lt;Person id:{self.id} name:{self.name}&gt;'
  
  class Pet(db.Model):
      __tablename__ = 'pets'
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(64), nullable=False, unique=True)
      owner_id = db.Column(db.Integer, db.ForeignKey('persons.id'), nullable=False)
  
      def __init__(self, *args, **kwargs):
          super(Pet, self).__init__(*args, **kwargs)
  
      def __repr__(self):
          return f'&lt;Pet id:{self.id} name:{self.name} owner_id:{self.owner_id}&gt;'
  </code></pre>
  
  <p>I`m trying to get persons list ordered by count of pets with this query:</p>
  
  <pre><code>persons = Person.query.order_by(Person.pets).all()
  </code></pre>
  
  <p>And getting this error:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: pets.owner_id
  [SQL: SELECT persons.id AS persons_id, persons.name AS persons_name
  FROM persons ORDER BY persons.id = pets.owner_id]
  </code></pre>
  
  <p>What I`m doing wrong?
  I have a suggestion that I need to make a request with join(), but research in google did not give working solutions.</p>