-
Notifications
You must be signed in to change notification settings - Fork 37
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
How to create an edge in a transaction #72
Comments
I am sorry to ask it again but are there any solutions to create an egde in a transaction? |
Out of curiosity, but what leads you to believe you need a transaction to create an edge? Scott |
Makes sense to me. Sometimes a few records within a transaction could get connected. Besides, edge is also a record, if it's not a light edge. Therefore, any record should be able to be placed within a transaction Sent from my iPhone
|
Yes, if you are doing more than just creating an edge, you might want a transaction. But, isn't the creation of an edge atomic itself? Scott |
Thanks for your response. The clue is, that it is not allowed to have two edges between two vertices. Example: Users can vote the similarity between two movies. If there’s no connection, an edge (similarity) will be created. If one already exist, only the weight of the edge will be changed. Finally I have to check if a direct path exist between the two specific movies, if not I create one. So how should I avoid that two user vote the same movies at the same time? Is it possible to adjust that only one similar edge exist? Lightweight Edge is not a solution for me because I have a property on my edge. |
Your domain problem sounds similar to another thread I was discussing in the ODB Google group and I believe your logic problem is similar. To find out if someone has already done a "vote" (or rating), one would have to know about the votes (or ratings). That means, the votes are an object and should be a vertex and not an edge. Once votes are a vertex, then thinking logically about them becomes much easier. Working with them also becomes easier in ODB, because you can use the unique index on the relationships (the edges) between the votes, the users and the movies. You can do a lot more with that data structure, than you can with trying to make an edge work like an object, which it isn't. An edge should only signify a relationship. This is the structure I'd suggest. user <=voted=> similarity_vote <=similar_to=> movie1 So the logic is...
Check out this test on how a transaction (sh)could be used.(?) https://github.com/Ostico/PhpOrient/blob/master/tests/PhpOrient/TxCommitTest.php Maybe it might help. 😄 Scott |
Thank you for the detailed answer and I am sorry if we lose the focus of the question. I am open-minded for the structure and I had a similar one at the beginning. How do you select all similar movies of a reference movie for all user votes?
Example for current structure: How do you find out the similarity of movie 1 and 4 at the new structure? Is the new structure right?
Maybe it will help me if you send me the link of the ODB Google group discussing? |
Naw, the discussion in GG is a bit different. Now that you've explained a bit more, I understand your domain a bit better. I was under the impression, the votes had to be related to the users. If that isn't the case, then you are right. The relationship is the similarity and not the vote itself. This will probably show my incompetence, but how did you come up with the 10% similarity in your example? Scott |
Hey Scott. The calculation was:
Finally I still have the problem: how do I avoid that two user vote the same movies at the same time? |
Ahhh! See, I knew I was on to something. If you need to know about the votes made between users, then you need the votes as vertices. If you need the calculation of the relationships to each movie, that is a different graph. I would assume, the votes also change the amount of the relationship? So, you need both. movie <= similarity => movie and user <= voted => vote <= similar_to => movie1 Whether or not you can do the same calculation with only the lower graph, is beyond my own capabilities. Sorry.... Scott |
Hey Scott, thank you for your advice and your help. I will think about it. |
Yes, I am not denying the edge in this case should be created in a transaction with the other tasks that need to get done. Actually now digging into your code, what is Scott |
i'm having the same issue trying to create a bunch of edges with transactions, so tried a workaround using sqlBatch approach:
https://github.com/Ostico/PhpOrient#execute-orientdb-sql-batch |
I use PHP 5.5 and try to create an edge. I used the command function:
It worked fine but now I need it in a transaction. My code looks like the next example:
But I get an error by using commands in a transaction (ERROR: Wrong command type PhpOrient\Protocols\Binary\Operations\Command).
I changed the type and used recordCreate.
Finally my edge was created but only the edge had 'out' and 'in' parameters, not the verteces (vertex1, vertex2). If I use shortestPath of vertex1 and vertex2 it will not find any path. Does somebody has a solution for that problem?
The text was updated successfully, but these errors were encountered: