democracyworks / datomic-toolbox

Datomic Utility Library
19 stars 0 forks source link

Components are not handled properly #12

Open awkay opened 8 years ago

awkay commented 8 years ago

Using datomic pro, I see no way to make your :transact work with ref many to components.

You require that the nested components match perfectly, but use identity on components and de-id them, which means when I pull them I have to try to munge them around. Not only that, but your output does not even say what is expected vs actual.

When I change the implementation to this, it seems to work better, but perhaps you can enlighten me why you treat component refs different from non-component, since they are both entities...seems like checking by db/id is sufficient:

(let [entity   (d/entity db eid)
        relation (d/entity db rel)
        ->set (fn [maybe-set]
                (cond
                  (instance? java.util.Collection maybe-set) (set maybe-set)
                  (nil?  maybe-set) #{}
                  :else             #{maybe-set}))
        old-values (->set old-value)
        new-values (->set new-value)
        existing-values (map :db/id (->set (get entity rel)))
        de-id (fn [e]
                (if (instance? datomic.Entity e)
                  (into {} e)
                  e))
        actual (set (map de-id existing-values))]
    (when-not (= old-values actual)
      (throw (java.util.ConcurrentModificationException.
               (str "old-values do not match existing values: "
                 "Info: "
                 "expected: " (pr-str old-values) "; "
                 "actual: " (pr-str actual) "; "
                 "coll? " (instance? java.util.Collection old-value) "; "
                 "nil? " (nil? old-value) "; "
                 "type: " (type old-value)))))