How to search/sort by foreign key column? #514
Answered
by
aminalaee
anton-petrov
asked this question in
Q&A
-
Hi! I have a table with foreign key column, which points to another table (entity). So, I see that column in general list, and it's ok, but including this column in sqlalchemy.exc.CompileError: Can't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc. So, the question is how to sort/search by foreign object, for example, by it's name? I alreade have defined str method, but it doesn't help. Thanks for advance. |
Beta Was this translation helpful? Give feedback.
Answered by
aminalaee
Jun 11, 2023
Replies: 1 comment 3 replies
-
class DataSources(Base):
source_id = Column(SmallInteger)
...
def __str__(self):
return self.data_source_name if self.data_source_name else str(self.data_source_id)
class Devices(Base):
...
data_source_name = Column(Text, nullable=False)
data_source = relationship("DataSources", back_populates="devices") |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah thats missing for now, I will however take a look