Fork me on GitHub
#datomic
<
2017-12-10
>
sova-soars-the-sora00:12:42

What does the following mean? java.lang.String cannot be cast to clojure.lang.IPersistentMap

dominicm00:12:05

@sova it means you're using a string where you should be using a {}

sova-soars-the-sora00:12:37

Oh. Hmm let's see.

sova-soars-the-sora00:12:10

(GET "/k/:tag" [ tag :as ring-req ] (let [tag-result (f9db/get-blurb-by-tag tag)] {:status 200 :headers {"Content-Type" "text/html"} :body tag-result})) quantum jumped back down to something that works.

sova-soars-the-sora00:12:55

I see. It's more of a Ring thing.

sova-soars-the-sora00:12:06

Logic needs to live before you send a ring response map back

sova-soars-the-sora00:12:34

with {:body "" :session "" :headers "" :etc "tec"}

sova-soars-the-sora00:12:22

lessons learned tonight: else must live subordinately inside an if.

joelsanchez17:12:42

I think isComponent is not useful for collections of components, because to be able to use it I need to model the relation as n-m, while in most cases it should be 1-n To make my point concrete, I disagree with the example given in this URL: http://blog.datomic.com/2013/06/component-entities.html

{:db/id #db/id[:db.part/db]
 :db/ident :order/lineItems
 :db/isComponent true
 :db/valueType :db.type/ref
 :db/cardinality :db.cardinality/many
 :db.install/_attribute :db.part/db}
This allows one lineItem to be associated to more than one order, which should not be allowed (in my opinion), so I do this:
[{:db/ident :order.line/order
  :db/valueType :db.type/ref
  :db/cardinality :db.cardinality/one}
 {:db/ident :order.line/product
  :db/valueType :db.type/ref
  :db/cardinality :db.cardinality/one}
 {:db/ident :order.line/quantity
  :db/valueType :db.type/long
  :db/cardinality :db.cardinality/one}]
This way I get the desired 1-n relation but I can't use isComponent anymore 😞

favila19:12:00

isComponent and cardinality are orthogonal concepts. Use is-component when you need an entity to have value-semantics instead of identity-semantics @joelsanchez

joelsanchez19:12:56

@favila that clears it up a little bit, thanks

favila19:12:59

Also in your n-m example, note the reverse ref from line item to its parent is card-one not many

favila19:12:27

This is true of all isComponent attributes when followed backwards

joelsanchez19:12:18

yes, but when the :order/lineItems attribute exists, any order can refer to any lineItem, even those that are not of its ownership

joelsanchez19:12:24

but I guess I shouldn't worry about that

favila19:12:02

The implicit invariant with isCompnent data (which datomic assumes but does not check) is that there is only ever one reference to its value

joelsanchez19:12:43

makes sense for Datomic to assume so, since it deletes isComponent values when the referrer is deleted

favila19:12:28

More specifically, (d/datoms db :vaet the-component-entity) will only ever produce one datom, whose attr is an isComponent attr

favila19:12:28

So the lineitems should be wholly owned by their order, but datomic isn’t going to check for you

favila19:12:37

Your application should ensure it

favila20:12:13

(Owner transfership is possible too without breaking the invariant)

joelsanchez20:12:30

thanks for the explanation, it goes in a similar way to refs then 🙂 (you're allowed to refer to any entity but if your app requires a certain constraint you should handle it or write a db/fn)

favila20:12:12

Yes. IsComponent is a strange annotation in that it’s on attrs but it really asserts something about entities

favila20:12:33

It’s the closest thing to entity schema that exists natively

joelsanchez20:12:07

previously I thought about it as a sort of "ON DELETE CASCADE" equivalent

joelsanchez20:12:11

so...will be changing my schema! 😂