How to properly specify multiple belongs_to()
rules pointing to same table?
#500
-
I've hit an issue defining a table where a row contains two foreign keys from the same target table. For example: class User(Model):
primary_keys = ["user_id"]
user_id = Field.int()
name = Field().string()
birthday = Field.datetime()
has_many({"sent": "Whisper.sender_user_id"}, {"received": "Whisper.receiver_user_id"})
class Whisper(Model):
belongs_to({"sender": "User"}, {"receiver": "User"})
message = Field.text()
timestamp = Field.datetime() Running this will raise an error of It seems to stem from something similar to this StackOverflow post. Apparently the foreign keys need to be announced separately instead of all at the same time? Is that something I can do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
@kamakazikamikaze the has_many({"sent": "Whisper.sender"}, {"received": "Whisper.receiver"}) I also don't really get why you would define a |
Beta Was this translation helpful? Give feedback.
👍 I'll release a patch version the next week