Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Why .select().where(...).get() instead of .get(models.User.username**username)?

Why .select().where(...).get() instead of .get(models.User.username**username)?

What's the difference?

I'm reffering to this video: https://teamtreehouse.com/library/build-a-social-network-with-flask/broadcasting/stream-views

At 5:50

2 Answers

Hi there, my understanding is that ** means 'like' so in your first query you return an exact match where as the ** query you would return records that may not be an exact match but close enough.

Hope I got that correct and it makes sense.

I know this. I just don't know why to use .select().where(models.User.username*username).get() instead of simply .get(models.User.username*username) . What's the difference between .select().where() and .get() in this situation?

hi there - get() returns a single record and calls select() in the background - a shortcut. Just watched the video so in the case mentioned my understanding you can use either get or where as you only want to return a single user

Hopefully this answers what you want, apologies for not understanding the last time