One to Many Relationship Issues

One to Many Relationship Issues

  

Hi,

Working on a forum that allows users to select days and a time periods within those days. 

For Example, They may chose 02/10/2018 and within this day a time period 9:00 - 11:00.

However I want to allow multiple times periods per record, such as Date 02/10/2018, times 9:00 - 11:00 and 1:00 - 3:00.

I currently have a Time Entity that stores start and end times. and this is linked to to the Request Entity (this is were the date field is stored). The relationship is one to many from Request to Time.

The issue is that the forum is updating the Request Entity Attributes but not updating the Time Entity Attributes, in fact is not creating any time records at all.

Any help would be greatly appreciated

Peter 

Can you show us the action you're using to save these? 

This is the action once the button at the end of the forum is clicked. I am using the TimePicker from the forge so this is why the two assign statements are being used, to assign the start and end time to Request.Form.Time.StartTime and Request.Form.Time.EndTime. The CreateOrUpdateRequest is them being run with the source being RequestForm.Record.

(The section of the screen shot that is cut of is only validation checks)

I am aware that the current set up I am using still only allows one time period per day to be set, But since moving the time attributes to there own entity I have run into problems. 

Peter

So, shouldn't there be a CreateOrUpdateTime, where there should be at least the StartTime, EndTime, and RequestId?

Mariano Picco wrote:

So, shouldn't there be a CreateOrUpdateTime, where there should be at least the StartTime, EndTime, and RequestId?

Yes, the entity has StartTime, EndTime and RequestID. When I add the CreateOrUpdateTime action to the flow, I get an error. But shouldnt the CreateOrUpdateRequest action work for the Time entity attributes as they have a relationship between them.

For the forum I can access the Time attributes. So I thought this would allow me to assign values to the StartTime and EndTime attributes but the RequestID in Time is always 0  

Solution

I'm not sure if there's a way to make it automatically, but here I attached an example doing it by creating first the Request, then using the resulting RequestId to create a TimeRecord. This way you can have many Requests with the same date, and different hours, every one will create a new line in the Request table.


Does this help?

Solution

Mariano Picco wrote:

I'm not sure if there's a way to make it automatically, but here I attached an example doing it by creating first the Request, then using the resulting RequestId to create a TimeRecord. This way you can have many Requests with the same date, and different hours, every one will create a new line in the Request table.


Does this help?


Thanks for the example!! I will try and implement like you have done, and assign Times Records after the creation of the Request Record.

Thanks again

After thinking about it a little more, in this example, it's more like a one-to-one relationship, when afterwards you will need to sort of "group by" Request dates; 

If you really want to do a one to many, it probably would work more like:

Check if there are requests already existing for that date -> If a request with the date exists, use it and its Id; If not, create a new one and use that one's id. -> Create the TimeRecord, and associate it to the Id.