2
votes

have a pretty simple relationship already ORM defined in CF10. We have temperature sensors that have a many-to-one relationship defined in the tempSensor object to Buildings.

tempSensors ORM persistent component

id_tempSensor - PK currentReading - Integer value id_Space - many-to-one relationship to below PK

spaces ORM persistent component

id_space - PK name - string description - string

I want to do two things with this relationship:

  1. Write a function in the 'spaces' component that returns an array of all the tempSensors objects that are mapped to to it. Ordering/sorting of results is not critical; we can re-order if necessary using standard CF array functions.

  2. Write a function in the 'spaces' component that calculates the average temperature reading amongst all the tempSensors mapped to that space. So if there are five temp sensors mapped to that space, add up all the current temp readings, divide by five and return out the result.

I have looked all over for an easy solution to #1, maybe HQL to define a simple query?

I am thinking HQL might be the fastest and most efficient for #2, as we are going directly to the persistence layer, rather than return results in CF, instantiate objects and run arithmetic against the CF objects.

1

1 Answers

0
votes
  1. If you define the one-to-many relationship on your Space for property sensors of type array, then the function you're looking for is just getTempSensors() that returns the array of sensors.

  2. once you got #1 working, just loop through the array and calculate your avg temp.

http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WS5FFD2854-7F18-43ea-B383-161E007CE0D1.html#WSDDE3349B-ECE1-450d-B5B1-0BCACDCC6736