0

many-manyユーザーとオークションの間に というテーブルがありますplacedBids

私はオークションからクエリを行っているので、オークションからアクセスできるように backref も呼び出します。たとえば、入札さplacedBidsれた入札の(これは、 と呼ばれる別の backref がすでにあるため、変更しましたが、問題がある可能性があります)それを試みるために、私は多くのことを試しました。placedbidsuseridusernameuserplacedbidsuserbidsuserssqlalchemyuserbids

これは私の最後のクエリです:

auction = dbsession.query(Auction.id, Auction.endTime, Auction.currentPrice, Product.description, Product.title, User.username, PlacedBids.timeplaced, PlacedBids.userbids.username).outerjoin(Auction.placedbids).join(Auction.products).outerjoin(Auction.leader).filter( Auction.id == request.matchdict['id']).all()

エラー:

2012-05-18T16:40:36+00:00 app[web.1]: AttributeError: 'InstrumentedAttri bute' オブジェクトにも 'Comparator' オブジェクトにも属性 'username' がありません

outerjoin(Auction.placedbids.userbids)などなどにも参加してみPlacedBids.userbidsましたが…

問題なく取得できる を取得するsqlalchemyために追加のクエリを作成できますが、それなしで作成する方法を知りたいです。usernameuser_id

4

1 に答える 1

0

結合は常に明示的である必要があり、実際の親クラスの観点からリードエンティティ属性を指定する必要があります。関連するクラス間に「複数の点線の」アクセスはありません。これは、常に個別に指定する必要がある結合を意味します。

ここでPlacedBids.userbidsがUserBidのインスタンスであると仮定します。

auction = dbsession.query(Auction.id, Auction.endTime, 
   Auction.currentPrice, Product.description, Product.title, User.username, 
    PlacedBids.timeplaced, UserBid.username).\
    outerjoin(Auction.placedbids).\
    join(Auction.products).\
    outerjoin(Auction.leader).\
    outerjoin(PlaceBids.userbids).\ 
    filter( Auction.id == request.matchdict['id']).all()
于 2012-05-23T15:42:53.903 に答える