mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix FK from entity to doc
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""Document model for tracking files in the knowledge base."""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from typing import Optional, List
|
||||
|
||||
from sqlalchemy import String, DateTime, text, JSON
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from basic_memory.models.base import Base
|
||||
|
||||
@@ -33,5 +33,12 @@ class Document(Base):
|
||||
onupdate=text("CURRENT_TIMESTAMP")
|
||||
)
|
||||
|
||||
# Relationships
|
||||
entities: Mapped[List["Entity"]] = relationship(
|
||||
"Entity",
|
||||
back_populates="document",
|
||||
cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Document(id={self.id}, path='{self.path}')"
|
||||
@@ -5,7 +5,7 @@ from typing import List, Optional
|
||||
|
||||
from sqlalchemy import (
|
||||
String, DateTime, ForeignKey, Text, Integer,
|
||||
text, UniqueConstraint, ForeignKeyConstraint
|
||||
text, UniqueConstraint
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
@@ -51,6 +51,10 @@ class Entity(Base):
|
||||
)
|
||||
|
||||
# Relationships
|
||||
document: Mapped["Document"] = relationship(
|
||||
"Document",
|
||||
back_populates="entities"
|
||||
)
|
||||
observations: Mapped[List["Observation"]] = relationship(
|
||||
"Observation",
|
||||
back_populates="entity",
|
||||
|
||||
Reference in New Issue
Block a user