This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-08
Channels
- # bangalore-clj (5)
- # beginners (6)
- # boot (66)
- # cider (48)
- # cljsrn (14)
- # clojure (699)
- # clojure-austin (2)
- # clojure-berlin (1)
- # clojure-boston (5)
- # clojure-dev (3)
- # clojure-india (7)
- # clojure-italy (24)
- # clojure-nl (5)
- # clojure-russia (33)
- # clojure-spec (30)
- # clojure-uk (64)
- # clojure-ukraine (22)
- # clojurescript (123)
- # clojurewest (1)
- # cursive (18)
- # datascript (44)
- # datomic (12)
- # dirac (46)
- # figwheel (1)
- # gsoc (5)
- # hoplon (6)
- # immutant (29)
- # instaparse (1)
- # juxt (26)
- # lein-figwheel (5)
- # leiningen (4)
- # luminus (8)
- # mount (56)
- # off-topic (60)
- # om (67)
- # om-next (1)
- # onyx (8)
- # proton (28)
- # re-frame (125)
- # ring (3)
- # ring-swagger (3)
- # specter (22)
- # testing (2)
- # unrepl (1)
- # untangled (91)
Hey guys! I'm using a datascript DB with the following schema:
(def schema
{:form/id {
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
:form/key {
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
:form/content {
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}
:field/name {
:db/cardinality :db.cardinality/one}
:field/label {
:db/cardinality :db.cardinality/one}
:field/type {
:db/cardinality :db.cardinality/one}
:field/validations {
:db/cardinality :db.cardinality/many}
})
Now, whenever I add a form (`d/transact! conn [form])` with the same key twice, the form/id gets overwritten just like expected. The form/content however is not overwritten, but appended to (resulting in a form with each field twice). I feel like there should be a nicer way than checking for existence and then retracting the entity manually before re-adding a form...so you need to compare each and every attribute in a field to decide whether it’s the same or a new one
If I wanted to add new fields this way, yes. What I'd like to happen is to have the :form/content refer to a whole new collection of fields once I re-enter a form with the same key
I also don’t think it’s a good practice on its own. You’d probably want to update matching fields, not remove them and inserting anew
@linuss So I've been there a few times. I also did the remove/add thing for a while. And even carefully checked and then transacted the difference. All worked well... until it didn't. Lots of bugs. Much easier is to give those child elements an identity.
Then all the upserts work really well and lots of headaches are gone. All that needs to be done, is to just always give them some composite key that identifies them.
I am trying to update a value in datascript. I have empty database with schema:
"DB_IDENT": {
":db/unique": ":db.unique/identity"
},
"current": {
":db/valueType": ":db.type/ref"
}
and I am writing a function:
function setMyAddress(db, myAddr, oldAddr=null){
return ds.db_with(db, vector(vector(DB_RETRACT, vector("DB_IDENT", "myAddr") , "current", toClj({"myAddr": oldAddr})),
vector(DB_ADD, vector("DB_IDENT", "myAddr") , "current", toClj({myAddr}))))
}
and it is sayign that "Expected number or lookup ref for entity id, got {"myAddr" nil}"
When you insert a map into attribute which is marked as ref in a schema, it will be expanded into whole new entity automatically
But on retraction theres no magic, you have to delete what you want to delete, exactly as it's stored
That's why it asks about entity id or lookup ref. It can't delete a map because a map is not stored there