나는 placedBids
이라는 사용자와 경매 사이에 many-many
테이블을 가지고 있습니다.쿼리 및 정보를 얻으십시오. 2 backrefs deep
나는 내가 경매에서 액세스 할 수 있습니다 또한 placedbids
라고 placedBids
에 역 참조 그래서 경매에서 질의하고, 다음 내가 예를 들어, 배치 입찰의 userid
를 얻을 수 있습니다,하지만 난 정말 그것 username
을 원하는, 그래서 내가 만든 user
과 placedbids
사이의 관계에있는 역 참조 (이 문제는 users
라고하는 이미 다른 백 레퍼런스가 있기 때문에 변경되었습니다. 어쨌든 거기에 어떤 문제가 있습니다.) 새로운 것을 시도했습니다. sqlalchemy
많은 것을 시도해 보았습니다. userbids
backref에서 열심히로드하는 것은 아무 소용이 없습니다.
이 내 마지막 쿼리입니다 :
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()
오류 : 나는 또한 outerjoin(Auction.placedbids.userbids)
또는 PlacedBids.userbids
등처럼에 합류 시도
2012-05-18T16:40:36+00:00 app[web.1]: AttributeError: Neither 'InstrumentedAttri bute' object nor 'Comparator' object has an attribute 'username'
...
난 몰라 sqlalchemy
에 대한 많은 경험이 있습니다. 추가 문의는 username
을 user_id
와 함께 할 수 있습니다. 문제는 없지만 그걸 만들지 않는 방법을 알고 싶습니다.
userbids이 사용자에 대한 역 참조가되고, 및 사용자에의 관계가 잘 보여주고 있음을 내가 이미 Auction.leader에서 User.username를 사용, 그렇다면 PlacedBids.userbids에서 액세스 한 다음 어쩌면 그 별칭의 별칭을 만들 수 있습니까? 감사합니다 –
auction = dbsession.query (Auction.id, Auction.endTime, Auction.created, Auction.currentPrice, Product.description, Product.title, User.username, PlacedBids.timeplaced, PlacedBids.user_id, user_alias.username) .outerjoin (Auction.leader) .outerjoin (user_alias, PlacedBids.userbids) .filter (Auction.id == request.matchdict [ 'id']). all()가 작동했습니다. (Auction.placedbids) .join ! 어쨌든 고마워, 내가 훌륭한 아이디어를 제외하고 몇 가지 아이디어를 제외시켰다. –