Skip to content

Instantly share code, notes, and snippets.

@tell-k
Created September 14, 2012 07:25
Show Gist options
  • Save tell-k/3720499 to your computer and use it in GitHub Desktop.
Save tell-k/3720499 to your computer and use it in GitHub Desktop.
class Entry(Base):
__tablename__ = 'entries'
id = Column(Integer, primary_key=True)
text = Column(String(200))
created_at = Column(DateTime, default=datetime.now, nullable=False)
comments = relationship('Comment', backref="entry",
primaryjoin="Entry.id==Comment.entry_id", # <- ここ
foreign_keys="Comment.entry_id") # <- ここ
class Comment(Base):
__tablename__ = 'comments'
id = Column(Integer, primary_key=True)
entry_id = Column(Integer, nullable=False) # <= ForeignKeyを外す
text = Column(String(200))
created_at = Column(DateTime, default=datetime.now, nullable=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment