Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transacting many ref value as set of inline maps #476

Closed
aiba opened this issue Jul 4, 2024 · 2 comments
Closed

Transacting many ref value as set of inline maps #476

aiba opened this issue Jul 4, 2024 · 2 comments

Comments

@aiba
Copy link

aiba commented Jul 4, 2024

This worked in 1.6.5:

(require '[datascript.core :as d])

(def schema {:item/tags {:db/valueType :db.type/ref
                         :db/cardinality :db.cardinality/many}})

(def conn (d/create-conn schema))

(d/transact! conn [{:db/id "1"
                    :item/tags #{{:tag/name "foo"}
                                 {:tag/name "bar"}}}])

In 1.7.1, it throws an error, "Expected number or lookup ref for entity id, got nil".

I tracked it to the new function, assoc-auto-tempids, which only assigns tempids to inline maps of a many ref value if the value is sequential?, which sets are not. So now one must use a sequential value, such as:

(d/transact! conn [{:db/id "1"
                    ;; Vector, not set.
                    :item/tags [{:tag/name "foo"}
                                {:tag/name "bar"}]}])

But I think it's logical to be able to transact many ref entities inline as a set of maps, since that's also how they are returned when queried.

Is this as simple as changing This line to check coll? rather than sequential??

@tonsky
Copy link
Owner

tonsky commented Jul 4, 2024

Yeah sorry about that. Try 1.7.2

@aiba
Copy link
Author

aiba commented Jul 5, 2024

Working great in 1.7.2, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants