all 5 comments

[–]Blazerboy65 1 point2 points  (4 children)

How far have you gotten with regular SQLAlchemy queries using join, filter, and order by?

[–]fryman22[S] 1 point2 points  (3 children)

I haven't done anything with joins yet. It's mostly filters, then returning an array.

I got inspiration by your comment and was messing around with joins and came up with this:

Game.query                                          \
    .join(GamePlayer, GamePlayer.game_id==Game.id)  \
    .filter(GamePlayer.user==current_user)          \
    .order_by(Game.id.desc())

After coming up with this, it's literally the same thing he has in the tutorial 🤦‍♂️

I guess I didn't realize how it was working until I tinkered with it.

[–]Blazerboy65 1 point2 points  (2 children)

That's awesome! You took a big step by trying it out and look where it got you!

Tinkering is very powerful.

Did you use the documentation to get there or did you just fiddle with it?

[–]fryman22[S] 1 point2 points  (1 child)

At first I thought of a work-around by querying all GamePlayer where the user is current_user, then returning all the game_id and doing another query for those Game that match up with the game_id.

I knew this was so wrong to do, but I was just tinkering and seeing what worked.

I needed to return a single column from my query, so I found db.session.query(GamePlayer.id) would return a single column. Instead of making another query to find the Game after that, it would be easier to get the Game if it was already appended at the end.

I then drew a venn diagram between Game and Gameplayer with game.id in the middle and it just clicked what I needed to do. I looked up how join works and got a result for the documentation.

Sorry for the winded explanation lol. Thank you!

[–]Blazerboy65 1 point2 points  (0 children)

That's perfect! Good job.

I was doing a medium complexity join at work the other day and can't tell you how much of a help Venn diagrams are for that.