Created
August 2, 2019 14:10
-
-
Save matthavener/4e61cf3db97fde90cde56af0d556ba6b to your computer and use it in GitHub Desktop.
datomic isComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(do | |
(d/delete-database "datomic:mem://test-is-component") | |
(d/create-database "datomic:mem://test-is-component") | |
(let [conn (d/connect "datomic:mem://test-is-component") | |
db (-> (d/transact conn [{:db/ident :dev/ref, | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many | |
:db/isComponent true}]) | |
deref | |
:db-after) | |
{:keys [db-after tempids]} (d/with db [{:db/id "parent1" | |
:db/doc "parent1" | |
:dev/ref "child"} | |
{:db/id "parent2" | |
:db/doc "parent2"} | |
{:db/id "child" | |
:db/doc "child"} | |
]) | |
db-a db-after | |
; move child to parent2? | |
db-b (:db-after (d/with db-a [[:db/add | |
(get tempids "parent2") | |
:dev/ref | |
(get tempids "child")]]))] | |
; child's parent is still parent1 | |
(assert (= (:dev/_ref (d/entity db-b (get tempids "child"))) | |
(d/entity db-b (get tempids "parent1")))) | |
; parent1 and parent2 both "own" child | |
(assert (= (:dev/ref (d/entity db-b (get tempids "parent1"))) | |
(:dev/ref (d/entity db-b (get tempids "parent2"))))) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment