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

Reverse on :db/isComponent attributes has a special case for reading. #138

Merged
1 commit merged into from
Nov 11, 2014

Conversation

scott-abernethy
Copy link
Contributor

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:

@dwhjames
Copy link
Owner

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 Long.

However, another approach could be to add an alternative to reverse, for example,

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.

@scott-abernethy
Copy link
Contributor Author

No problem. :)
Having the single entity returned would be better, as it removes the redundant singleton set. I'm happy to go with the reverseComponent solution. I made the change, added a test for the read[Long] case, and rebased.

@ghost
Copy link

ghost commented Nov 11, 2014

In hindsight, I wish I’d gone with reversed, rather than reverse. When combined to make reverseComponent, it sits even more uncomfortably… as it sounds like an action on a component.

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 one and many can’t be computed with a dependent type.

Any suggestions for something better than reverseComponent? Or do you think it is livable?

@scott-abernethy
Copy link
Contributor Author

Naming, the hardest problem in comp sci...
I'm fine with it.
I did consider adding the component type to Attribute originally, but it seemed like overkill so I ditched the idea.

@ghost
Copy link

ghost commented Nov 11, 2014

Yeah, that extra type information would come at a pretty high cost in terms of noise everywhere else, just to solve that problem.

@scott-abernethy
Copy link
Contributor Author

Ooops, used tabs.

@ghost
Copy link

ghost commented Nov 11, 2014

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.

ghost pushed a commit that referenced this pull request Nov 11, 2014
Reverse on :db/isComponent attributes has a special case for reading.
@ghost ghost merged commit 186d59e into dwhjames:develop Nov 11, 2014
This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants