diff --git a/src/datahike/db/utils.cljc b/src/datahike/db/utils.cljc index fb589403..904fe9bc 100644 --- a/src/datahike/db/utils.cljc +++ b/src/datahike/db/utils.cljc @@ -149,7 +149,6 @@ (defn attr-has-ref? [db attr] (and (not (nil? attr)) - (not (ds/built-in-attribute? attr)) (:attribute-refs? (dbi/-config db)))) (defn attr-ref-or-ident [db attr] diff --git a/src/datahike/schema.cljc b/src/datahike/schema.cljc index 1266e67d..50cbd82b 100644 --- a/src/datahike/schema.cljc +++ b/src/datahike/schema.cljc @@ -214,10 +214,5 @@ (= "db" (first (clojure.string/split ns #"\."))) false))) -(def built-in-attributes #{:db/ident}) - -(defn built-in-attribute? [x] - (contains? built-in-attributes x)) - (defn get-user-schema [{:keys [schema] :as db}] (into {} (filter #(not (is-system-keyword? (key %))) schema))) diff --git a/test/datahike/test/attribute_refs/differences_test.cljc b/test/datahike/test/attribute_refs/differences_test.cljc index 08dc4d01..ffd10869 100644 --- a/test/datahike/test/attribute_refs/differences_test.cljc +++ b/test/datahike/test/attribute_refs/differences_test.cljc @@ -309,15 +309,50 @@ (is (not (nil? (d/transact conn [[:db/add next-eid :db/ident :name]])))) (d/release conn))) - (testing "Keyword transaction in reference DB" - (let [[no-ref-cfg ref-cfg] (init-cfgs) - conn (setup-db ref-cfg) - next-eid (inc (:max-eid @conn))] - (is (thrown-with-msg? Throwable - (re-pattern (str "Bad entity attribute :db/ident" - " at \\[:db/add " next-eid " :db/ident :name\\]," - " expected reference number")) - (d/transact conn [[:db/add next-eid :db/ident :name]]))) + (testing "Using :db/ident attribute" + (doseq [cfg (init-cfgs) + :let [attribute-refs? (:attribute-refs? cfg) + conn (setup-db cfg) + next-eid (inc (:max-eid @conn)) + init-datoms (d/datoms + @conn + {:index :aevt + :components [:db/ident]})]] + + ;; Check that the database with attribute-refs? being true + ;; contains some initial atoms, and otherwise none. + (is (= (boolean (seq init-datoms)) + (boolean attribute-refs?))) + + ;; Transact a datom for attribute :db/ident. This + ;; must work no matter the value of :attribute-refs? + (is (some? (d/transact + conn + [[:db/add next-eid :db/ident :name]]))) + + ;; Check that we can access the datom just transacted + ;; using d/datoms. + (let [datoms (d/datoms @conn + {:index :aevt + :components [:db/ident]})] + (is (= (inc (count init-datoms)) + (count datoms))) + (is (some (fn [[_ a v]] + (and (= v :name) + (or attribute-refs? + (= a :db/ident)))) + datoms))) + + ;; Check for a more specific query. + (let [[ident-name-datom :as ident-name-datoms] + (d/datoms @conn + {:index :avet + :components [:db/ident + :name]})] + (is (= 1 (count ident-name-datoms))) + (is (= :name (:v ident-name-datom))) + (is (or attribute-refs? + (= :db/ident (:a ident-name-datom))))) (d/release conn)))) (deftest test-transact-data-with-reference-attr