-
Notifications
You must be signed in to change notification settings - Fork 8
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 put unique constraints for multiple properties? #62
Comments
There is no officially supported way to do this for constraints with multiple properties, at least not for now. Though there is a fairly good workaround you could do to support these type of constraints in your data model. The trick is that Blueprint41 does not support constraints of this type, but also doesn't try to micro manage them. If you added the constraint manually, Blueprint41 will not touch this type of constraint when it's managing the supported Unique constraints. This comes with a few caveats though:
[Version(..., ..., ...)]
public void HackCompositeConstraint()
{
// Run a data migration if a real database is connected, this is not part of the managed schema.
DataMigration.Run(delegate ()
{
// Instead of managing data, we write the constraint directly in the graph.
DataMigration.ExecuteCypher("CREATE CONSTRAINT [CONSTRAINT_NAME_HERE] FOR (node:[LABEL_HERE]) REQUIRE (node.[FIELD_HERE], node.[FIELD_HERE]) IS UNIQUE");
});
} You could add some code to your StartUp() to warn you when Bluerpint41 gets proper support for this feature: MyModel model = new MyModel()
model.Execute(true);
#if DEBUG
using (Transaction.Begin())
{
if (!Transaction.Current.Run("show constraints").Select(item => item.Values["name"]?.ToString()).Any(item => item == "[CONSTRAINT_NAME_HERE]"))
throw new NotSupportedException("REMINDER!!! BP41 now supports constraints for multiple properties, plz add them to the model the proper way.");
}
#endif Hope this solves your problem for now! |
Please let us know how to put unique constraints for multiple properties.
I can't see any option other than Add property in Data store to add uniqueness, which holds true for only single property.
The text was updated successfully, but these errors were encountered: