0

I want to get all the values from the row for a query, however when I run the below code it returns an object instead of the values:

Session = sessionmaker()
Session.configure(bind=engine)  #
session = Session()

class Player(Base):
    __tablename__ = 'player_alc'
    id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
    name = Column(String(50))
    country= Column(String(50))
    first_name = Column(String(50))
    last_name= Column(String(50))


class Player_Mapping(Base):
    __tablename__ = 'player_external_id_mapping_alc'
    external_id = Column(String(50), nullable=False, primary_key=True)
    external_source_name = Column(String(50), nullable=False, primary_key=True)
    id = Column(Integer, ForeignKey('player_alc.id'))
    Player = relationship("Player", back_populates="player_mapping")

Player.player_mapping = relationship(
"Player_Mapping",  back_populates="Player")


query= session.query(Player_Mapping).filter_by(external_id=external_id, external_source_name=external_source_name).one()

Above code returns the following value for the query:

ORM_classes.Player_Mapping object at 0x0000016119E24D30>

1 Answer 1

2

You are asking for the object, right here:

session.query(Player_Mapping)

You can access all the fields through the returned object though, for example query.Player or query.external_source_name.

If you want to explicitly get the columns rather than an object, you can use:

session.query(Player_Mapping.Player, Player_Mapping.external_source_name)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.