A Composition of one
can be updated via the Parent Entity, like we would do it, when dealing with an Association to one
.
1 2 3 4 5 6 7 8 | entity myEntity : cuid , managed { field1 : String ; comp : Composition of one myComposition ; } aspect myComposition : cuid , managed { myCompField : String ; } |
1 2 3 4 5 6 7 8 9 | const { myEntity } = srv . entities const EntityComposition = srv . entities [ 'myEntity.myComposition' ] // composition srv . after ( 'CREATE' , EntityComposition , async ( comp , req ) = > { await UPDATE ( myEntity , comp . ID ) . set ( { comp : [ { myCompField : 'test' } ] } ) } ) |
A Composition of many
must be updated via the actual Composition Entity.
1 2 3 4 5 6 7 8 | entity myEntity : cuid , managed { field1 : String ; comp : Composition to many myComposition ; } aspect myComposition : cuid , managed { myCompField : String ; } |
1 2 3 4 5 | const EntityComposition = srv . entities [ 'myEntity.myComposition' ] // composition srv . after ( 'CREATE' , EntityComposition , async ( comp , req ) = > { await UPDATE ( EntityComposition , { up__ID : comp . up__ID , ID : comp . ID } ) . set ( { myCompField : 'test' } ) } ) |