typedb-driver
typedb-driver copied to clipboard
Make `RelationType.set_relates` return the created role
Problem to Solve
Currently, RelationType.set_relates
returns Promise[None]
. This is pretty inconvenient, as a lot of the time we then want to perform further operations on the newly created role. Unlike the put
methods for creating thing types, there is no parallel for roles, so they need to be gotten with RelationType.get_relates
to continue operating on them like so:
message = transaction.concepts.put_relation_type("message").resolve()
message.set_relates(transaction, "sender").resolve()
message.set_relates(transaction, "recipient").resolve()
message_sender = response.get_relates(transaction, "sender").resolve()
message_recipient = response.get_relates(transaction, "recipient").resolve()
Proposed Solution
Make RelationType.set_relates
return Promise[RoleType]
instead of Promise[None]
, like so:
message = transaction.concepts.put_relation_type("message").resolve()
message_sender = message.set_relates(transaction, "sender").resolve()
message_recipient = message.set_relates(transaction, "recipient").resolve()