I have a model, Account, with two foreign keys / relationships to another
model, Users.
class Account(object):
@declared_attr
def customer_id(cls):
return Column(ForeignKey(User.id))
@declared_attr
def customer(cls):
return relationship(User, lazy='joined', foreign_keys=cls.customer_id)
@declared_attr
def reporter_id(cls):
return Column(ForeignKey(User.id))
@declared_attr
def reporter(cls):
return relationship(User, lazy='joined', foreign_keys=cls.reporter_id)
session.query(Account) gives me the correct join logic for eager loading.
The issue comes when I want to load this data into a pandas dataframe. The
joined columns show up labeled as users_1_colname and users_2_colname which
makes it unclear which came from reporter and which came from customer. I
know in a one off query I can use aliases but how can I have a certain
alias dedicated to a relationship? I don't want to manually generate the
query and I don't want to change the column names in pandas. I want users_1 to
always be labeled reporter and users_2 to always be labeled customer when I
query Account. Is this possible?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.