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

Unable to resolve tempids on :db.unique/identity refs #464

Closed
aiba opened this issue Apr 17, 2024 · 2 comments
Closed

Unable to resolve tempids on :db.unique/identity refs #464

aiba opened this issue Apr 17, 2024 · 2 comments

Comments

@aiba
Copy link
Sponsor

aiba commented Apr 17, 2024

When transacting data that contains an attribute that is both :db.unique/identity and :db.type/ref, it appears tempids don't work.

Example:

  (def schema {:user/email {:db/unique :db.unique/identity}
               :profile/user {:db/valueType :db.type/ref
                              :db/cardinality :db.cardinality/one
                              :db/unique :db.unique/identity}})

  (def conn (datascript/create-conn schema))
  
  (datascript/transact! conn
                        [{:db/id "A"
                          :user/email "joe@gmail.com"}
                         {:db/id "B"
                          :profile/avatar "face.jpg"
                          :profile/user "A"}])

This fails with:

Unhandled clojure.lang.ExceptionInfo
   Expected number or lookup ref for entity id, got "A"
   {:entity-id "A", :error :entity-id/syntax}
@aiba
Copy link
Sponsor Author

aiba commented Apr 17, 2024

Upon further reflection, it's pretty weird to have an attribute that is both a :db.type/ref and :db.unique/identity. We changed our schema to {:db/unique :db.unique/value}, and the transactions with tempids are working.

I'll leave this issue open in case there might be a reason to have a ref with unique identity in someone's schema.

@tonsky tonsky closed this as completed in 009c628 Apr 24, 2024
@tonsky
Copy link
Owner

tonsky commented Apr 24, 2024

Thanks! Should be fixed

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