aio-libs/aiohttp-demos

Defining model

kination opened this issue · 4 comments

Hello,
I'm currently referring polls demo for developing aiohttp server app.
One question is, there are guide about defining model in tutorial document, and it said model can be defined as class instead of using table.

class Question(Base):
    __tablename__ = 'question'

    id = Column(Integer, primary_key=True)
    question_text = Column(String(200), nullable=False)
    pub_date = Column(Date, nullable=False)

Is there any sample to develop in this way?

Thanks.

No.
Because you cannot use the given class directly but only access it by model anyway.
In the context, declarative class-based models are useless and confusing.

But you can still use the approach.

@asvetlov thanks for comment.
Actually, I've refer about this from this page. How about add message about your comment? Because somebody else could be confused like me...

Please create a pull request.
We discussed the subject with @gyermolenko about a year ago, pushing the decision into the docs makes sense.

@asvetlov Okay, got it.