Welcome! Please see the About page for a little more info on how this works.

0 votes
in Cloud by

Datomic documentation recommends modeling relationships in one direction only. So, if I have a reference "whole" on an entity "part", I don't need to declare another reference "parts" on an entity "whole". The following attribute declaration is enough.

{:db/ident       :part/whole
 :db/valueType   :db.type/ref
 :db/cardinality :db.cardinality/one}

Then, I can use :part/_whole as a key to fetch all parts of a "whole". Even though it works, it's counterintuitive at times.

Is there a way to create a permanent alias for the reverse relationship, equivalent to the pull pattern :as option?

(d/pull db '[* {[:part/_whole :as :whole/parts] [*]}] whole-db-id)

1 Answer

0 votes
by

No, we currently do not allow you to make a permanent alias. However, you could write a function to present this alias or are you saying that your example pull pattern does not work for displaying the alias in the results? Finally, this example was counterintuitive to me too, but perhaps that is because to my eyes the relationship between part and whole seems backwards. Is this exactly your schema or an example to try to capture the problem you were trying to solve for?

...