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 Build a Social Network with Flask How to Win Friends Relationship Model

Why are relationship columns named "from_user" and "to_user" ( instead of "user" and "follower")?

What is the convention or reason behind naming the relationship table columns "from_user" and "to_user"?

I had a bit trouble understanding how the joins work, until i renamed the fields to "user" and "follower" - with a stopgap of names "user_id" and "follower_id".

This code seems much easier to understand for me:

    def following(self):
        """The users that we are following"""
        return (
            User.select()   # Select all users
                .join(Relationship, on=Relationship.user)  # that are in relationship table via "users" field
                .where(Relationship.follower == self)  # where the relationship "follower" field contains "current user"
        )

Also the stopgap version: That also has the redundant User.id == Relationship.user_id parameter in the join clause which might be helpful with little bit of SQL knowledge:

    def following(self):
        """The users that we are following"""
        return (
            User.select()   # Select all users
                .join(Relationship, on=User.id == Relationship.user_id)  # join by user.id = relationship.user_id 
                .where(Relationship.follower_id == self)  # and follower_id = currentuser.id 
        )

Are there any cases where from_user and to_user make more sense? Or does it just seem to make more sense to me because i have seen similar naming before?