This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-13
Channels
- # beginners (28)
- # boot (3)
- # clara (9)
- # cljs-dev (127)
- # clojure (82)
- # clojure-belgium (3)
- # clojure-italy (7)
- # clojure-russia (2)
- # clojure-spec (4)
- # clojure-uk (2)
- # clojurescript (351)
- # data-science (3)
- # datascript (1)
- # datomic (24)
- # fulcro (15)
- # jobs (3)
- # juxt (16)
- # off-topic (2)
- # onyx (18)
- # parinfer (1)
- # pedestal (3)
- # perun (6)
- # re-frame (14)
- # spacemacs (20)
@hmaurer component only makes sense on refs, and i don’t think you can unique a ref. perhaps a schema code example to explain what you mean? 🙂
@robert-stuttaford Hi! Are you sure about this? I just tried :db/unique :db.unique/value
on a :db.type/ref
attribute and it seems to behave as expected
Which makes sense as, as far as I understand, a ref is just an ID (long or something?)?
(by behave as expected I mean it does throw an exception if trying to transact the same ref twice)
And an example would be “Users” who have an “Account”. If, in a particular application, each user has a distinct account which is referenced by :user/account
, then it makes sense to make :user/account
unique.
The reason why I mentioned :db/isComponent
is that it seemed to me that every ref that is a component should also be unique (as far as I can see)
Unless I am mistaken, the semantics of :db/isComponent
are that whenever a “parent” entity is retracted, its components are also retracted, recursively
Say you have two entities A and B, where B is a component of A (e.g. there is a ref from A to B with :db/isComponent true
)
I cannot think of a scenario in which you would want other entities to hold refs to B with the same attribute
The expected invariants of an isComponent are redundant with the unique-value invariants. If you want a little more safety, go ahead
An isComponent-referenced entity should only be in the V of a single datoms in the entire database (for a given t)
What is the reasoning for “should only be in the V of a single datoms”? I agree though, it’s the conclusion I came to regarding a given attribute