Skip to content

Transacting many ref value as set of inline maps #476

@aiba

Description

@aiba

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??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions