neomodel
neomodel copied to clipboard
`create_or_update` does not allow for specifying what unique fields to match
Problem
Currently, it is not possible to specify on what fields you want to apply the merge action when calling create_or_update. Meaning if you have a StructuredNode with two unique fields pk and name. And you want to update only based on name (don't have access to pk). You can't really update all at once using create_or_update, or you need to resort to an ugly hack:
...
Node.__required_properties__ = tuple([x for x in Node.__required_properties__ if x != "pk"])
Node.create_or_update(data)
...
Django's bulk_update has a similar feature, using unique_fields when calling bulk_create with update_conflicts=True.
https://docs.djangoproject.com/en/5.1/ref/models/querysets/#bulk-create
Solution
It should be fairly simple to add a parameter to select which required properties to use. Backwards compatibility can be supported by using required_properties if parameter is not specified.