edgedb

EdgeDB automatic backlink


My scheme looks like this:

module default {
    type Category {
        required title: str;

        multi subcategories: default::Category {
            constraint exclusive;
        };

        multi products: default::Product {
            constraint exclusive;
        };

        single parent := .<subcategories[is default::Category];
    }

    type Product {
        required title: str;

        required offerId: str {
            constraint exclusive;
        };

        required single category: default::Category;
    }
}

when I select product categories the link is empty enter image description here but when I select the product category it is defined enter image description here

Why is this happening? Should I somehow change my schema so that the links are created automatically?


Solution

  • These are two separate relations, you have to change one of them to a backlink to tell edgedb they're the same:

    products := .<category[is Product];
    

    See the link direction note under https://docs.edgedb.com/database/datamodel/links#one-to-many