memgraph / gqlalchemy

GQLAlchemy is a library developed with the purpose of assisting in writing and running queries on Memgraph. GQLAlchemy supports high-level connection to Memgraph as well as modular query builder.

Home Page:https://pypi.org/project/gqlalchemy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unique Constaints on multiple fields

ilyatbn opened this issue · 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.

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?