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

:xform is not called on ref attributes #455

Closed
mortenschioler opened this issue Oct 11, 2023 · 2 comments
Closed

:xform is not called on ref attributes #455

mortenschioler opened this issue Oct 11, 2023 · 2 comments

Comments

@mortenschioler
Copy link

I want to dereference tag enumeration entities as part of a pull expression. For example:

(pull db [{[:user/preferred-lang :xform #(:db/ident %)] [:db/ident]}] eid)

;; expected
;; => {:user/preferred-lang :lang/en}

;; actual
;; => {:user/preferred-lang {:db/ident :lang/en}}

Unfortunately, this doesn't work -- I've boiled it down to being because xforms don't get called for reference attributes:

(let [res (d/with (d/empty-db {:a-ref-attr {:db/valueType :db.type/ref}})
                 [[:db/add -1 :db/ident :a-tag]
                  [:db/add -2 :a-ref-attr -1]])
      ent-id (get-in res [:tempids -2])
      db (:db-after res)]
  (d/pull db [[:a-ref-attr :xform (fn [%] (println "xform was called") 42)]] ent-id))
;;; [SILENCE -- NO PRINT, and value is not 42 but #db{:id 1}]
=> {:a-ref-attr #:db{:id 1}}
@mortenschioler mortenschioler changed the title :form is not called on ref attributes :xform is not called on ref attributes Oct 11, 2023
@tonsky tonsky closed this as completed in 941c2b1 Oct 17, 2023
@tonsky
Copy link
Owner

tonsky commented Oct 17, 2023

Thanks! Should be fixed in 1.5.4

@mortenschioler
Copy link
Author

Wow, cool @tonsky! 💯 Thank you so much for your work on DataScript. Am using it in a POC with re-frame, after reading Into The Tar Pit, and am loving it.

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