reifyhealth / specmonstah

Specmonstah will eat the face off your test fixtures
MIT License
359 stars 18 forks source link

How to keep relationships when recording to db? #56

Closed ignorabilis closed 4 years ago

ignorabilis commented 5 years ago

We're looking at this library since it can alleviate entity generation for each test. After trying to use it though a few things are unclear, with the main one being:

Ideally we want to transact all entities in a single tx. Each entity would have a string id, which can be used as tempid by Datomic; then each relation will be kept automatically.

For example:

;; schema
{:person {:prefix :p
               :spec   :sm/person}
 :company {:prefix :co
                   :spec   :sm/company}
 :membership {:prefix    :mem
                        :spec      :sm/membership
                        :relations {:membership/group  [:company :id]
                        :membership/member [:person :id]}}}

;; query 
{:person     [[:p0 {:spec-gen {:person/title "me"}}]]
 :membership [[1 {:refs {:membership/member :p0}}]]}

;; ents result
{:co0 {:company/name "3VxGlbNFWLVW3v7cn4", :id 66},
 :mem0 {:id 2, :membership/group 66, :membership/member 22},
 :p0 {:person/email "W30lkwEo6w-Wx@xW.com",
      :person/first-name "Oe",
      :person/last-name "D4oy8HOU98RR",
      :id 22}}

;; tx (not possible right now)
[{:company/name "3VxGlbNFWLVW3v7cn4", :db/id "66"},
 {:db/id "2", :membership/group "66", :membership/member "22"},
 {:person/email "W30lkwEo6w-Wx@xW.com",
  :person/first-name "Oe",
  :person/last-name "D4oy8HOU98RR",
  :db/id "22"}]

Not sure if this is possible in some other way or if I'm missing something - let me know if that's the case!

flyingmachine commented 5 years ago

@ignorabilis I'm not sure what the issue is? Is the problem that the id's are ints when you'd like them to be strings? From what I can tell:

And that seems right to me?

flyingmachine commented 4 years ago

Going to close this as I haven't heard a response, but please feel free to respond if this is still an issue :)