python - SQLAlchemy .all() only returning first result on multi-join -
howdie do,
so i'm joing 5 tables using following query:
order = db.session.query(trailer, trip, trippallet, waveorder, package)\ .join(trip, trailer.trailer_id == trip.trailer_id)\ .join(trippallet, trip.trip_id == trippallet.trip_id)\ .join(waveorder, trippallet.pallet_id == waveorder.pallet_id)\ .join(package, waveorder.order_id == package.order_id)\ .filter(trailer.trailer_id == '555555').all()
now, 5 tables follows:
**trailer table** trailer_id 555555 **trip table** trip_id trailer_id 523462462 555555 **trip pallet table** trip_id pallet_id 523462462 1052 523462462 1054 **wave order table** pallet_id order_id 1052 123456 1052 123457 1054 324567 1054 797453 **package table** order_id tracking 123456 abckdf 123457 dvniuo 324567 dnklin 797453 adfnln
so give overview, trailer contains trip. trip contains pallets , each pallet contains waves grouping of packages.
the query i'm using above return packages on 1 pallet, it's not returning pallets.
when run query, via loop, result:
counter = 0 trailer, trip, trippallet, wave_order, package in order: counter += 1 print "%d trailer id %d , contains trip id %d pallet id %d , has following order %d " \ "has following tracking number %s" % \ (counter, trailer.trailer_id, trip.trip_id, trippallet.pallet_id, wave_order.order_id, package.tracking_no) 1 trailer id 555555 , contains trip id 523462462 pallet id 1052 , has following order 123456 has following tracking number abckdf 2 trailer id 555555 , contains trip id 523462462 pallet id 1052 , has following order 123457 has following tracking number dvniuo
as can see, it's getting first pallet_id trip pallet table 1052. should getting pallet_id 1054 , returning packages on table.
does know how make return second pallet_id trip pallet table , it's corresponding packages?
howdie do,
the issue wasn't join statement. join statement 100% correct. in fact, database.
the dba had removed key data needed complete join statement.
Comments
Post a Comment