Fork me on GitHub
#datascript
<
2022-04-30
>
zeitstein07:04:56

A simplified example of my data model to illustrate the behaviour I need:

(def schema
    {:uuid     {:db/unique :db.unique/identity}
     :children {:db/valueType   :db.type/ref
                :db/cardinality :db.cardinality/many
                :db/isComponent true}
     :wraps    {:db/valueType   :db.type/ref
                :db/isComponent true}})
  
  (def conn (d/create-conn schema))

  (d/transact! conn
    [{:uuid 1 :children [{:uuid 2}]}
     {:uuid 3 :wraps {:uuid 2}}])
  
  (d/transact! conn [[:db.fn/retractEntity [:uuid 1]]])
What I would like to happen is retractEntity to detect 2 is also a component of 3 and consequently retract 1 without retracting 2. I'm not sure it would make sense for DataScript to have this behaviour by default, so I'm not suggesting that. Rather I'm trying to determine whether there is a way to get this behaviour without writing my own custom retractEntity? (This example is simple, but I'm usually dealing with large trees, so I prefer to fall back on existing facilities if at all possible.)

Linus Ericsson07:05:24

I cant see a way to do this with retractEntity. I think you will have to write a custom logic for this one.

zeitstein10:05:02

Thanks for confirming it, appreciate it.