1

Is it possible to add multiple enums to an attribute in datomic ? Something like :

[{:artist/name "Leonard Cohen" :artist/countries [:country/GR :country/CA] } 

In this case I get something like ":db.error/not-an-attribute :country/GR is not an attribute"

However

[{:artist/name "Leonard Cohen" :artist/countries :country/GR } 

would work

2
  • 1
    How is the schema definition for the :artist/countries attribute? Commented Jun 3, 2017 at 16:52
  • 1
    @GuillermoWinkler : [{:db/ident :artist/countries :db/valueType :db.type/ref :db/cardinality :db.cardinality/many Commented Jun 3, 2017 at 20:51

1 Answer 1

2

Please see the James Bond example in the Tupelo-Datomic library. In short, when adding multiple enum attributes you need to wrap them in a set instead of a vector:

; Create some antagonists and load them into the db. We can specify some of the ; attribute-value pairs at the time of creation, and add others later. Note that ; whenever we are adding multiple values for an attribute in a single step (e.g. ; :weapon/type), we must wrap all of the values in a set. Note that the set ; implies there can never be duplicate weapons for any one person. As before, ; we immediately commit the new entities into the DB. (td/transact *conn* (td/new-entity { :person/name "James Bond" :location "London" :weapon/type #{ :weapon/gun :weapon/wit } } ) (td/new-entity { :person/name "M" :location "London" :weapon/type #{ :weapon/gun :weapon/guile } } ) (td/new-entity { :person/name "Dr No" :location "Caribbean" :weapon/type :weapon/gun } )) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.