-
Notifications
You must be signed in to change notification settings - Fork 26
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
Reverse on :db/isComponent attributes has a special case for reading. #138
Conversation
Sorry for the slow response. So, if we take this approach, then I’d also like to apply the same code in the type class instance that returns just the entity id However, another approach could be to add an alternative to def reverseComponent(implicit ev: =:=[DatomicRef.type, DD]): Attribute[DatomicRef.type, Cardinality.one.type] = {
require(isComponent.getOrElse(false))
copy(
ident = clojure.lang.Keyword.intern(ident.getNamespace, "_" + ident.getName),
valueType = SchemaType.ref,
cardinality = Cardinality.one
)
} This would give just the parent entity when used, rather than the entity in a singleton set. |
00ba23a
to
d800d84
Compare
No problem. :) |
In hindsight, I wish I’d gone with Unfortunately, it’s not possible to combine the two methods into one as the component flag is not present at the type level, so the choice between Any suggestions for something better than |
Naming, the hardest problem in comp sci... |
Yeah, that extra type information would come at a pretty high cost in terms of noise everywhere else, just to solve that problem. |
Ooops, used tabs. |
d800d84
to
faa214b
Compare
Thanks for catching that. I spent a little while with @rjsvaljean brainstorming alternative names. We didn’t really come up with anything demonstrably better, so we can keep it as is. |
Reverse on :db/isComponent attributes has a special case for reading.
Fixes a 'bug' where RichEntity.read can not be used for reversed attributes that are components, due to an undocumented special case in datomic.Entity.get. Datomisca is expecting a collection but receives a single entity response, and throws an exception.
We've run in to this issue a few times, and had to drop down to using Entity.getAs.
Refer: