multiple foreign keys #3807
StackTrace18
announced in
Q&A
Replies: 1 comment 4 replies
-
@StackTrace18 What code have you tried? Can't you just set them as different foreign key fields? class App(rx.Model, table=True):
...
class Event(rx.Model, table=True):
app_id1: int = Field(foreign_key=f"{App.__tablename__}.id")
app_id2: int = Field(foreign_key=f"{App.__tablename__}.id") Or do you mean an arbitrary (unknown) amount of references, like a list of ids? In that case, the recommended way is to make a third table that joins the two together. class AppEvent(rx.Model, table=True):
app_id: Field(foreign_key=f"{App.__tablename__}.id")
event_id: Field(foreign_key=f"{Event.__tablename__}.id") The other option is to just store it as a stringified json list, but this won't have the foreign key integrity constraints. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create attributes for database objects with more than one foreign key relationships to the same object(s) e.g. object(s) with multiple many to many relations between them.
Tried sqlalchemy docs but still unclear in reflex.
Any ideas? Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions