The-Don-Himself / gremlin-ogm

A PHP Object Graph Mapper for Tinkerpop 3+ compatible Graph Databases (JanusGraph, Neo4j, etc.) that allows you to persist data and run gremlin queries.
MIT License
17 stars 2 forks source link

GraphTransformers #5

Closed juhasev closed 6 years ago

juhasev commented 6 years ago

So if I understand correctly there is really no way to automatically map Vertices / Edges back to PHP objects. It seems like the twitter graph does this completely manually using files in GraphTransformers folder. Shouldn't there be a universal reverse mapper as well or even better use the classes (models) that already exist for Graph Schema?

The-Don-Himself commented 6 years ago

Transforming vertices /edges back to PHP objects is no mean feat, consider this, the default use of graph traversal is moving from one element to another.

So perhaps you can say get users out comments in articles as articles out tags where tag contains 'tech' by articles.

In this case we want all blog posts with comments and with the tag 'tech' (note, it's not the most efficient traversal.

Transforming this back to PHP objects means either; 1.) We assume the dev only wants articles and not the associated objects (comments, tags, users). This would be easy to achieve. 2.) We assume the dev knows how to write complex gremlin queries to save each element (edge, vertex) as he/she traverses so as to output the full tree. articles -> tags & comments -> users. This is harder but we can write examples to showcase this. 3.) We assume the dev does not wants the object tree but that may not always be the case, as with the traversal above, one may want,

So perhaps you can say get users as users out comments in articles as articles out tags where tag contains 'tech' by (users, articles).

In this case we want all blog posts with comments and with the tag 'tech' and the users who made them. How do we transform this back to PHP objects?

In the end, I resolved that traversals back to objects was highly dependent on a case by case basis. That doesn't mean we can't whip something up for the most general cases, and make traversals back to objects an opt-in feature. What do you think?

juhasev commented 6 years ago

The more I think about this it makes less and less sense. We are all so used to thinking like RDBMS where object mapping straight to tables makes more sense, but even there when you get more and more complex things become hairy in terms of query performance, lazy loading etc... I've added a basic remapping back to PHP objects for Vertices and it works well but only when you are interested retrieving single vertex values.

The-Don-Himself commented 6 years ago

I know this question is closed, but it still bugs me that the ogm doesn't have any way or even recommendations of how to transform back to objects. In my own app, I created specific classes to handle it, since some times you need only the first element of the array (since graphs like JanusGraph always return arrays even when you sent single values), sometimes you need the full array like when tagging blog posts.

It's still very tricky to handle every use case, but I really think we should have at least some basic examples for the twitter graph. I'll sleep over it over the next few weeks and see what we should do, but if you have any suggestions or ideas, please don't hold back.