8000 Fix backref relationship in UserBook table · Issue #3 · noelis/LitBits · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix backref relationship in UserBook table #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
noelis opened this issue Dec 13, 2016 · 0 comments
Open

Fix backref relationship in UserBook table #3

noelis opened this issue Dec 13, 2016 · 0 comments

Comments

@noelis
Copy link
Owner
noelis commented Dec 13, 2016

Fix the variable name in backref:

Right now it says:

    user = db.relationship("User",
                        backref="user")

It should be:

user = db.relationship("User", backref="userbook")

full example:
`class UserBook(db.Model):
""" Books that the user has read and rated. """

# This is a middle table

__tablename__ = "user_books"

user_book_id = db.Column(db.Integer,
                    autoincrement=True,
                    primary_key=True)
user_id = db.Column(db.Integer,
                    db.ForeignKey("users.user_id"),
                    nullable=False)
book_id = db.Column(db.Integer,
                    db.ForeignKey("books.book_id"),
                    nullable=False)
book_read = db.Column(db.Boolean,
                    default=False,
                    nullable=False)
rating = db.Column(db.Integer,
                    nullable=True)
updated_at = db.Column(db.DateTime,
                    nullable=True)

book = db.relationship("Book",
                    backref="user_books")
user = db.relationship("User",
                    backref="user")

def __repr__(self):
    """ Provide helpful representation of ratings when printed"""

    return "<Book book_id=%s user_id=%s rating=%s>" % (self.book_id, self.user_id, self.rating)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0