-
Notifications
You must be signed in to change notification settings - Fork 276
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
Cannot add relations to unpersisted nodes #816
Comments
My opinions on this sort of thing:
Soooo... what I'd do here is:
The key here is that the process of creating/saving/finding nodes is completely separate from the process of creating the relationships. You can put that same callback and others in the ActiveRel classes, but you should be able to trust that the nodes are persisted because that isn't the relationship model's problem. If there is a problem, the transaction protects you from putting anything in an unhealthy state, and you should catch that problem early on so there are no surprises. How's that? I'll be signed into our Gitter room all day tomorrow, feel free to pop in if you want to work through this or anything else. http://gitter.im/neo4jrb/neo4j. |
BTW, you can find lots of info about ActiveRel at https://github.com/neo4jrb/neo4j/wiki/Neo4j%3A%3AActiveRel. |
This is biting me too when trying to implement authorization logic. I am new to Neo4j, so not all the concepts of the graph have sunk in yet, but having everything created inside a transaction and then check if I could have done that breaks my brain a bit. author = Author.create(name:'Author')
book = Book.new(title:'Title', author:author)
book.title # => 'Title'
book.author # => nil - ???, assignment should raise an error at least |
@beno I think the book.author is transactional since author is a relational reference and not a property, it couldn't find the relationship since book.save has not triggered. I could be wrong about this. |
Basic support for association creation with unpersisted nodes was added recently. It will clear up the initial issue, so I'm going to close this. |
I have the following use case, a bridge class between a Person and an Event called an Invitation. This is all scratch code, so please try to see the intent and not the actual sketchy Ruby I'm laying down.
If I want to ensure that the
:inviter
has permission to send the invitation, it seems I should handle that as a validation - something like,The problem is that the event can never be valid because none of the relations can be established until the node is saved - results in a
Neo4j::ActiveNode::HasN::NonPersistedNodeError
. But the invitation should never be saved unless the relations can be established and checked. Any idea how to manage this? Is there a best-practice or convention around this? I'd even settle for an anecdotal success story heard third-hand from a semi-reliable source.The text was updated successfully, but these errors were encountered: