TypeScript error when specifying `relationName` in a one-to-one relation
Hi there! I have the following relations:
The example code shows a case where the
referralCode
table has 2 fields that reference the user
table, so specifying relationName
is required to disambiguate. However, the config object taken by the one
function requires the fields
and references
properties, which doesn't make sense for the user
table which does not have foreign key fields.
For some reason, the many
function does not have this problem, and specifying just relationName
is fine.
Please let me know if I'm doing something wrong here.2 Replies
If I understood this correctly, a user can have many referal codes
Meaning, the relation is one to many
If it's just one, then you can use userId as the field and referralCode as the reference
you can use userId as the field and referralCode as the referenceDuh, I didn't think this was possible since the FK is in
referralCode
instead of user
, but it makes sense given that relations and FKs are completely separate. This works perfectly. Thank you!