Match attributes in entities from different objects

0
I would like to match 2 different objects in different entities by a date value that is in both entities.   the entities receive the info from 2 api’s.   One api gives me the amount of rain per day: Root 1 – * Rain with in rain the attributes date and rain_mm   then other api is similar and gives the hours of sun per day: Root 1 – * Sun with in sun the attributes date and sun_hours   I have a ListView from object Rain with dates and rain_mm. I want the user to select the object in the list and then show from the other entity the hours of sun in the attribute sun_hours in the object with the same date.   The dates are unique in the entities and in the same format.   How to filter the object in Sun by date from the date attribute in the selected object from Rain?
asked
2 answers
2

I don’t know the data stream but as you already described, could match the two data sources by at least the day/date as a common identifier.

There might be multiple approaches now, depending on how/if you are storing the api data in your app.

If you have both data streams persistent in your database and just keep on adding new data using the api, you could use a simple xPath to retrieve eg. the sun hours data using the timestamp of the rain data (vice versa).

https://docs.mendix.com/refguide/xpath . The two timestamps you are comparing do not even have to match up to the exact hour/minute/second.. as you can use eg. day, month and year from date time.  https://docs.mendix.com/refguide/xpath-day-from-datetime

Maybe this is already what you are looking for?

 

answered
0

Changing your domain model can help you out here. You think you have two entities, “I would like to match 2 different objects in different entities”, but actually you have two attributes of one entity “Date”. As you describe: “The dates are unique in the entities”. So instead of entity RainPerDate and HoursOfSunPerDate, you are better off defining one entity Date with two attributes RainPerDate and HoursOfSunPerDate and have the 2 API's upsert (insert if the Date object does not exist yet, change it if it does) the result in entity Date’s attribute.

Once having done that, your matching problem is gone.

answered