Authors and their books

Report a typo

Below, you can see a code that represents the connection between two tables: authors and their books.

from sqlalchemy.orm import relationship


class Author(Base):

    __tablename__ = "author"

    id = Column(Integer, primary_key=True, autoincrement="auto")
    username = Column(String(255), unique=True, nullable=False)
    first_name = Column(String(255))
    last_name = Column(String(255))
    

class Book(Base):
 
    __tablename__ = "book"

    id = Column(Integer, primary_key=True, index=True)
    author_id = Column(Integer, ForeignKey("author.id"))  
    book_name = Column(String(255), nullable=False)
    
    author = relationship("Author")

   

What type of relationship is this?

Pay attention to where relationship() is declared.

Select one option from the list
___

Create a free account to access the full topic