Fork me on GitHub
#datascript
<
2020-02-09
>
richiardiandrea01:02:20

Hi there, I have a question...I have data in this shape:

({:product/code "42"
  :sku/code "1"
  :product/names [{:product/name "Camera"
                   :language/iso-639-1 "en"}
                  {:product/name "Appareil"
                   :language/iso-639-1 "fr"}]
  :product/type "Camcorders & Digital Cameras"}
 ...)
and schema
(def schema {:product/code {:db/unique :db.unique/identity}
             :product/names {:db/valueType   :db.type/ref
                             :db/cardinality :db.cardinality/many
                             :db/isComponent true}
             :language/iso-639-1 {:db/valueType   :db.type/ref
                                  :db/isComponent true}})
Is it expected that I see these datoms?
[1 :product/code "42" 536870913 true]
[1 :product/names 2 536870913 true]
[1 :product/names 4 536870913 true]
[1 :product/type "Camcorders & Digital Cameras" 536870913 true]
[1 :sku/code "1" 536870913 true]
[2 :language/iso-639-1 3 536870913 true]
[2 :product/name "Camera" 536870913 true]
[4 :language/iso-639-1 5 536870913 true]
[4 :product/name "Appareil" 536870913 true]
If yes, why is it not showing me the language in:
(datascript/pull db ["*"] 3)
=> #:db{:id 3}

richiardiandrea01:02:13

In the above the entity 3 should have attribute "en" but I never see it in the list of datoms

richiardiandrea02:02:10

I am basically trying to have one datom per :language/iso-639-1 and refer to those from the product/name

richiardiandrea04:02:07

Oh I see, if it's a ref I cannot really go back to the values - kind of makes sense

richiardiandrea04:02:08

I wonder how I can model that now though

richiardiandrea05:02:07

(as a note, I am letting datascript create the entities, no :db/add on my side)

richiardiandrea05:02:01

uhm...I see I receive back some

(:tempids txs)
{"en" 3, "fr" 5, :db/current-tx 536870913}
still not clear ... digging digging

richiardiandrea21:02:51

for my problem above, I am still trying to understand how to model, it feels like I need a composite key [:product/name :language] - is it something you usually do in datascript/datomic?