AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with
<p>I have a table defined as </p>

<pre><code>class Results(db.Model):
    __tablename__ = 'results'
    event_id = db.Column(db.Integer, db.ForeignKey(Events.id), primary_key=True)
    event = db.relationship('Events', foreign_keys='Results.event_id')
    team_id = db.Column(db.Integer, db.ForeignKey(Teams.id), primary_key=True)
    team = db.relationship('Teams', foreign_keys='Results.team_id')
    position = db.Column(db.Integer, default=0)
    rr_position = db.Column(db.Integer, default=0)
    score = db.Column(db.Float, default=0)
</code></pre>

<p>and </p>

<pre><code>class Teams(db.Model):
    __tablename__ = 'teams'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    country = db.Column(db.String(64), nullable=False)
</code></pre>

<p>When I run the following</p>

<pre><code>r = Results.query.all()
print(len(r))
</code></pre>

<p>I get 138 rows.</p>

<p>If I run</p>

<pre><code>r =  db.session.query(Teams.name
    , Results.team_id
    , Results.event_id).all()
print(len(r))
</code></pre>

<p>or </p>

<pre><code>r = Results.query.add_column(Teams.name).all()
print(len(r))
</code></pre>

<p>then I get 6072 rows. With this query, I am expecting 138 rows and one team name for each.</p>

<p>But if I try</p>

<pre><code>r ==  db.session.query(Results.team.name
    , Results.team_id
    , Results.event_id).all()
</code></pre>

<p>I get the following error</p>

<p>AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Results.team has an attribute 'name'</p>