gqlalchemy icon indicating copy to clipboard operation
gqlalchemy copied to clipboard

Unique Constaints on multiple fields

Open ilyatbn opened this issue 2 years ago • 1 comments

considering the following Node class:

class DataSet(Node):
    id: str = Field(exists=True, db=connection)
    item_type: str = Field(exists=True, db=connection)
    ...

How do I make a unique constaint for both fields using the Node class?

I can achieve this manually by adding the following outside of the class:

connection.create_constraint(MemgraphConstraintUnique(label='DataSet', property=('id', 'item_type')))

If I set each field with a unique=True property the constraint is created separately for each field and I only want them to both be the same to be considered unique.

ilyatbn avatar May 21 '23 21:05 ilyatbn

Hi @ilyatbn, thank you for reporting this. It is impossible to specify multiple properties when creating uniqueness constraints by extending Node class. But I can see you managed to find the workaround! Thank you for pointing this out! I will leave this issue open so we can plan to add it as a feature. You are also more than welcome to contribute!

What are you working on?

katarinasupe avatar May 23 '23 15:05 katarinasupe