I have a schema looking like this where I abstracted out the contact information:
type Address {
required property location -> str{
constraint max_len_value(100);
};
}
type Phone{
required property number -> int32{
constraint min_value(0);
constraint max_value(9999999999);
};
}
abstract type Contact {
multi link address -> Address{
constraint exclusive;
on target delete delete source;
};
multi link phone -> Phone{
constraint exclusive;
on target delete delete source;
};
}
type User extending Contact{
required property name -> str{
constraint max_len_value(40);
constraint exclusive;
};
required property rank -> str{
constraint max_len_value(40);
};
}
type Worker extending Contact{
required property name -> str{
constraint max_len_value(40);
};
required property job -> str{
constraint max_len_value(40);
};
}
If I want to limit the choices when doing a reverse query for the Address and Phone to inputs only related to User for User and only Worker for Worker (So queries are restricted by the previous inputs for the object [eg. you cant query the address for User in to be added to Worker]). The relationship is a many to one relationship.
There are two ways I can do this but what is the best practice for efficiency for Edgedb. Would I use the backlink like this:
type Address {
required property location -> str{
constraint max_len_value(100);
};
link in_user := .<address[is User]
link in_worker := .<address[is Worker]
}
type Phone{
required property number -> int32{
constraint min_value(0);
constraint max_value(9999999999);
};
link in_user := .<phone[is User]
link in_worker := .<phone[is Worker]
}
Or should I use a foreign key link (like in SQL) like this:
type Address {
required property location -> str{
constraint max_len_value(100);
};
link in_user -> User{
on target delete delete source;
};
link in_worker -> Worker{
on target delete delete source;
};
}
type Phone{
required property number -> int32{
constraint min_value(0);
constraint max_value(9999999999);
};
link in_user -> User{
on target delete delete source;
};
link in_worker -> Worker{
on target delete delete source;
};
}