Creating a new record in 2 entities

Hello, I am very new to Outsystems and was hoping someone could help me.

I have 3 entities - Employee, Post and PostImage

Each Post is associated with an employee and a Post image via EmployeeId and PostImageId. In my Post details form, I have included the PostImage field


and my SaveDetail client action is in Screenshot attached.


When I click Save on the form, a record is created in the Post entity, but there is no PostImage created with the image uploaded and the PostImageId field in the newly created record in Post entity is 0.

Is my understanding of how this should be done correct? Would appreciate any advice on how something like this should be done. Thank you!!



Screenshot20210804at12.48.46AM.png

Hello @Yu Hsin Seah,

How are you selecting an image before Save?
For e.g. do you upload an image and then expect it to be inserted into the database? Or are you selecting the image from the PostImage Entity?

Regards,

AJ

Hi! I am just clicking on the image box and uploading an image, and trying to get it inserted into the PostImage Entity, not selecting an existing image from the PostImage Entity. Thanks!

I would suggest the following flow for Save:

1. Insert/ update record in the Post Entity.
2. Get the Post Identifier for the record that was just inserted/updated
3. Insert / update record in the PostImage Entity and pass the Post Identifier as an input parameter. Store the PostId and the PostImage binary in the PostImage Entity (so you can remove PostImageId from the Post Entity)

This way you can always display the Post record along with the image by joining the Post and PostImage tables on PostId.

With this design, if you wish to upload a different image to the same Post then you just update the record in PostImage with the new image each time.

Hope this helps

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.