I'm stuck on how to do this relation.
I have two mySQL models. One named 'Vehicles' and another named 'Checklist'. Evidently, Checklist contains a list of questions and a date field that is automatically generated.
I am making a reporting page, where I'm trying to list each vehicle vertically and then have 12 checkbox widgets horizontally across from each vehicle with a month label above.
I'm trying to get the checkbox's to only be to ticked if a checklist exists with the corresponding date field.
i.e.
> Vehicles -- January - February - March - April - May ...
> Vehicle A - [] - [] - [] - [] - [] ...
> Vehicle B - [] - [] - [] - [] - [] ...
> Vehicle C - [] - [] - [] - [] - [] ...
I've read the relations reference but I've hit a wall, not sure how to get this working.
Can somebody put me in the right direction?
For the value attribute of each checkbox widget, enter this code:
(@datasource.item.Checklist..Date || []).some(d => d.getMonth() === #)
Where Date is the name of the date field in the checklist table and change the # to the corresponding month of the checkbox (January = 0, February = 1, etc).
EDIT:
If you want to be able to check other aspects of the Checklist record, you could do something like this:
(@datasource.item.Checklist || []).some(c => c.Date.getMonth() === # && c.Status === 'Approved')