Fork me on GitHub
#datascript
<
2017-01-01
>
mrg19:01:55

fwiw this was the answer:

misha20:01:57

@mrg why not:

(def db (ds/create-conn {:supervisors {:db/cardinality :db.cardinality/many}}))

(ds/transact db [{:name "max" :supervisors [1 2 3]}
                 {:name "dilbert" :supervisors [1 2]}])

(defn supervised-by [supervisors]
  (ds/q '[:find [?e ...]
          :in $ [?supervisor ...]
          :where
          [?e :supervisors ?supervisor]]
    @db supervisors))

(supervised-by [3])
=> [1]
(supervised-by [2 3])
=> [1 2]
(supervised-by [1])
=> [1 2]
(supervised-by [2])
=> [1 2]
or just:
(ds/q '[:find [?e ...]
        :in $ ?supervisor
        :where [?e :supervisors ?supervisor]]
  @db 3)
=> [1]
?

mrg20:01:25

oooh, that's how cardinality works?

mrg20:01:46

Thank you @misha, this is great!

misha20:01:50

@mrg you'd probably need to have

{:supervisors {:db/cardinality :db.cardinality/many :db/valueType :db.type/ref}}
if you want to look up by references, not by integer attributes, like e.g. price, etc.

misha20:01:16

omitted it for example brevity.

mrg20:01:56

I haven't really come across datascript schemas yet. Setting the value type to ref would mean that this is a reference to another entity, right?

misha20:01:00

I think you need to invest few hours in these: http://www.datomic.com/training.html

mrg20:01:27

I think so too. Thanks for the pointer.

mrg20:01:10

That's what I'm reading right now 🙂

misha20:01:09

it might not behave exactly as in datomic, but it'll get you 95% (or even 100% for many use cases) there

mrg20:01:45

Probably close enough.

mrg20:01:56

It's a very big topic; too big to dive in without a project to guide the reading, but then you come across things like my problem that you don't understand without having seen the right approach at some points

mrg20:01:20

And then you're at an impasse unless someone points you in the right direction. Thanks again

mrg20:01:27

I know what to read up on next now 🙂

misha20:01:42

I'd start with videos

notanon20:01:20

the stu and tim ewalds videos were a good place to start for me