I have tried to use datomic alias feature both for entities and attributes by using function db/add and I got strange behaviour. First case when I’m trying to set aliasing for entities:
E.g. the next schema is transacted:
(def user-schema [
{
:db/ident :user/code
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/unique :db.unique/value
}
{
:db/ident :user/firstName
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
}
{
:db/ident :user/lastName
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
}
])
(d/transact conn user-schema)
Then I’m creating entity:
(def user-data [
{
:db/ident :user/fistLastNames
:user/firstName “FirstName”
:user/lastName “LastName”
:user/code “code1”
}
])
(d/transact conn user-data)
Then I’m setting an alias
(d/transact
conn
[[:db/add :user/fistLastNames :db/ident :person/fistLastNames]
])
If to check entity using both idents it points to the same entity
Which ID is 17592186045427, so everything looks, aliasing works well, but once I’m trying to update entity
(def user-data [
{
:db/ident :user/fistLastNames
:user/lastName “LastNameFixed”
:user/code “code1”
}
])
(d/transact conn user-data)
I’m getting: “Unique conflict: :user/code, value: code1 already held by: 17592186045427 asserted for: 17592186045430”
Actually I’m interested in doing such operations for attributes too, and everything is good even when updating already aliased attribute but using original ident, but the same actions do not work if an updated attribute is part of other attribute(mentioned in :db/tupleAttrs). I’m getting:
:db.error/cannot-retarget-ident Ident :user/firstName cannot be used for entity 95, already used for :person/firstName"
I tried the next schema:
(def user-schema [
{
:db/ident :user/firstName
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
}
{
:db/ident :user/lastName
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
}
{
:db/ident :user/fullName
:db/valueType :db.type/tuple
:db/tupleAttrs [:user/firstName :user/lastName]
:db/cardinality :db.cardinality/one
}
])
(d/transact conn user-schema)
Then I did:
(d/transact
conn
[[:db/add :user/firstName :db/ident :person/firstName]
[:db/add :user/lastName :db/ident :person/lastName]
[:db/add :user/fullName :db/ident :person/fullName]
])
So, when I’m trying to transact:
(def alter-user-schema [
{
:db/ident :user/firstName
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
}
])
(d/transact conn alter-user-schema)
Then I’m getting the above mentioned error, but when attribute is not part of other tuple attribute then all is good