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