on 08-19-2023 12:44 AM
Hi everyone,
I have a cds schema that has the composition entities defined inside the parent entity, for example:
entity Product : cuid {
type : StyleType;
style : Style;
categories : Composition of many {
key ID : UUID;
categoryType : String(1);
categoryNumber: String(1);
}
}
And I want to define an @assert.unique for ID up__ID and Category type :
@assert.unique.style : [
ID,
up__ID,
categoryType,
categoryNumber,
]
But I get compile messages errors like this:
message: '“@assert.unique.style”: “categoryType” has not been found'.
If I define my categories entity outside and I define the @assert.unique.style like this:
entity Product : cuid {
type : StyleType;
style : Style;
categories : Composition of many Categories on categories.parent = $self
}
@assert.unique.style : [
parent,
categoryType,
categoryNumber,
]
entity Categories: cuid {
parent: Association to Product;
categoryType : String(1);
categoryNumber : String(1);
}
it works, but I want to know if it is possible to define it when the composition of many is not defined outside, because this will save me a lot of work to redefine my schema, views, etc.
Thanks,
Tatiana F.
You can do that by using the `annotate` directive:
annotate Product.categories with @assert.unique.style : [
ID,
up_, // you have to set the unique constraint on the association
categoryType,
];
However, I think the unique constraint in this combination is pretty useless, as "ID" and "up_" are the primary key tuple, hence there can never be more then one record stored with the same "ID" and "up_" combination. Consequently there can never be two rows where "ID", "up_" and "categoryType" are the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
72 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.