eager_sales_persons = session.query(SalesPerson).options(joinedload(SalesPerson.customers).joinedload(Customer.addresses))
#with SalesPerson being a class I added with a relationship to customers.
However, the above statement raises: 'AssociationProxy' object has no attribute 'property'
I tried eager_sales_persons = session.query(SalesPerson).options(joinedload(SalesPerson.customers).joinedload(Customer.address_association).joinedload(AddressAssociation.addresses)).all()
however, it would emit SQL for customer.addresses.
I have made a pastie with my code at: http://pastie.org/9676017
Is there a loader strategy that would work for my situation or a work around for the AssociationProxy error?
Thank you so much for your help :)
~Victor
Thank you so much for your help :)
~Victor
--
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 sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
eager_addresses = session.query(Address).options(joinedload(Address.association).joinedload(Customer.assoc_cls.parent, Supplier.assoc_cls.parent)).all()
2014-10-26 09:52:25,099 INFO sqlalchemy.engine.base.Engine SELECT address.id AS address_id, address.association_id AS address_association_id, address.street AS address_street, address.city AS address_city, address.zip AS address_zip, address_association_1.id AS address_association_1_id, address_association_1.discriminator AS address_association_1_discriminator
FROM address LEFT OUTER JOIN address_association AS address_association_1 ON address_association_1.id = address.association_id
eager_addresses = session.query(Address).options(joinedload(Address.parent))
#error sqlalchemy.exc.ArgumentError: mapper option expects string key or list of attributes
eager_addresses = session.query(Address).options(joinedload(Address.association).joinedload(Customer.assoc_cls.parent), joinedload(Address.association).joinedload(Supplier.assoc_cls.parent)).all()
#not joining to Customer or Supplier
eager_addresses = session.query(Address).outerjoin(Address.association).outerjoin(Customer.assoc_cls.parent).options(contains_eager(Address.parent)).outerjoin(Supplier.assoc_cls.parent).options(contains_eager(Address.parent).all())
#error sqlalchemy.exc.ArgumentError: mapper option expects string key or list of attributes
On Nov 24, 2014, at 1:00 AM, Victor Reichert <vfr...@gmail.com> wrote:I've taken another look at trying to eager load the address.parent. Is it possible to do that?
I've tried a couple of ways, pasted a below. My full code is at: https://gist.github.com/vfr292/a5939418285e4c8bd03b
On Nov 24, 2014, at 12:31 PM, Michael Bayer <mik...@zzzcomputing.com> wrote:
On Nov 24, 2014, at 1:00 AM, Victor Reichert <vfr...@gmail.com> wrote:I've taken another look at trying to eager load the address.parent. Is it possible to do that?Unfortuntately not really. It should be in theory but I’m not able to work out an eager load that goes to both Customer and Supplier in terms of AddressAssociation at the same time. I can get the query to render just fine but the eager-targeting logic at the moment doesn’t seem to know how to be told to go to two separate subclasses of a base class at the same time. There’s probably improvements yet to be made in eager loading to support this case better, e.g. this is a bug, but I’ve wrestled with it for about an hour and I’m out of time on it for now, sorry. Even if it works, the query is very unpleasant to look at :) If I get it working later I’ll send it out.
On Nov 24, 2014, at 5:16 PM, Michael Bayer <mik...@zzzcomputing.com> wrote:
On Nov 24, 2014, at 12:31 PM, Michael Bayer <mik...@zzzcomputing.com> wrote:
On Nov 24, 2014, at 1:00 AM, Victor Reichert <vfr...@gmail.com> wrote:I've taken another look at trying to eager load the address.parent. Is it possible to do that?Unfortuntately not really. It should be in theory but I’m not able to work out an eager load that goes to both Customer and Supplier in terms of AddressAssociation at the same time. I can get the query to render just fine but the eager-targeting logic at the moment doesn’t seem to know how to be told to go to two separate subclasses of a base class at the same time. There’s probably improvements yet to be made in eager loading to support this case better, e.g. this is a bug, but I’ve wrestled with it for about an hour and I’m out of time on it for now, sorry. Even if it works, the query is very unpleasant to look at :) If I get it working later I’ll send it out.OK here we go, the limitation is that the of_type() modifier is only recognized along a particular path once. So to get over this we can use a with_polymorphic():
poly = with_polymorphic(
AddressAssociation,
[Customer.assoc_cls, Supplier.assoc_cls], aliased=True)
eager_addresses = session.query(Address).options(
joinedload(Address.association.of_type(poly)).joinedload(
poly.CustomerAddressAssociation.parent),
joinedload(Address.association.of_type(poly)).joinedload(
poly.SupplierAddressAssociation.parent),
).order_by(poly.discriminator.desc(), poly.id)