0

Say I have two table definitions like so:

class Item(Base):
    __tablename__ = "items"
    __table_args__ = {"schema": "my_schema"}
    id = Column(Integer, primary_key=True)
    category= Column(Integer)

class Other(Base):
    __tablename__ = "others"
    __table_args__ = {"schema": "my_schema"}
    id= Column(Integer, primary_key=True)
    some_other_category= Column(Integer)

In my handler, I am creating an engine, like so:

engine = self.connector.get_engine()
        Base.metadata.create_all(engine)

Now my goal is to define a query that performs a join of these two tables:

    def process(self):

        query = select(Item).join_from(Other, Other.id)

        # The actual execution is hidden for the sake of readability.
        # Simple selects on both tables individually work just fine.

        result = some_helper.fetch_connection(query)
        print(result)
        return result

The error I get is the following, on which I can find no explanation:

sqlalchemy.exc.ArgumentError: Join target Other.id does not refer to a mapped entity

What am I doing wrong here?

Ipsider
  • 553
  • 1
  • 7
  • 20

0 Answers0