Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-27-2019 09:10 PM
I've made this same question in StackOverflow, but I'm asking here as well to increase the odds of getting some help.
I'm aware that using the "relationship property existence constraint" available in Neo4j Enterprise I can force relationships of a given label to have some properties, for example:
(Relationships of label "LIKED" always have a "day" property)
CREATE CONSTRAINT ON ()-[like:LIKED]-() ASSERT exists(like.day)
But is it possible to force relationships from a node label X to a node label Y to have specific properties? An example of what I would like to do would be:
(Relationships of label "BOUGHT" from/to nodes label "Person" to/from nodes label "Book" always have a "day" property)
CREATE CONSTRAINT ON (p:Person)-[bo:BOUGHT]-(b:Book) ASSERT exists(b.day)
But that isn't considered a valid Cypher command. Is there a way to achieve this effect at a schema level or would I need to implement it in the application layer? Thank you.
03-28-2019 05:42 AM
Hey welcome to the community! Right now there there's no way to ensure those constraints exist via the neo4j schema you'd have to figure out a way to do that in your application layer.
03-28-2019 08:06 AM
Michael,
I think with triggers you can do it right in Neo4j. Read David Allen's response to a question on triggers: Triggers -- matching vs filtering on trigger criteria
I believe you can create a trigger which upon creation of a relationship of type RELTYPE will kick off arbitrary code that you write, which can check the nodes it connects to and based on their types you can make changes to any of the 3 objects connected. They are all within scope.
Joe
03-28-2019 08:40 AM
Thank you guys for your input, I'll be sure to try and implement a solution based on triggers, as @neo4joe suggested. It seems to be the best alternative for dealing with this kind of requirement outside the application layer. I'll post my results here once I've attempted writing the solution.
12-22-2022 11:02 AM - edited 12-22-2022 11:35 AM
Hey, Gabriel here
Data enginer
Can you tell us more about what you are trying to archive,
Maybe there is an ever better solution based on your actual need who fits with what Neo4j as to offer?
As I understand, you want to enforce a date to exists when a Person, or in this case, a customer bought a book.
The question would be, who enter this date, how, and do they care about it?
Even if you enforce a day property to exists, it doesn't mean this one will be good, so you kind of already have to work on your app site to add more stuff like validate that it's an actual date in a proper format. Only with that you will be able to make good data analysis after while.
Shema constraints are good to make the graph make sens and avoid the worst, but to me, they don't replace data validation at all for future analysis. In short, constraints will not at all ensure that you can answer the simple question below:
How many books has been sold during this day / week / month etc.
All the sessions of the conference are now available online