Big question about a relationship setup

hello there all.
i have a question about how to set up a relationship thru another table
that i am using as kind of a pointer.
it works like this.

i have machines
each machine has_many: machine_options
machine_options table has an id, option_description, and sensor

i also have several other tables for each type of sensor
for example pressure_sensors, volt_sensors, flow_sensors etc…
each of these tables has a monitor that will match the monitor in
one of the type of machine_option

like this
machine 3 has a 2 options
so the rows for machine_options may look like this
machine_id = ‘3’, option_description = ‘pressure’, monitor =
‘23psi343’
machine_id = ‘3’, option_description = ‘volts’, monitor =
‘234vdc43’

so here is the part where i am stumped.

is there a way i can set up something that allows me to conditionally
link a table?
like IF option_description == ‘pressure’ then machine ‘3’ has_one
:pressure_sensor find by monitor = machine_option.monitor

Or if not, what would be a good suggestion of a way i could map this
out. or have a way to return a pressure_sensor object for a machine
with an option_description that == ‘pressure’

the last point that i think will not be a problem is each
pressure_sensor has an id. There is another table of
pressure_sensor_records that records the history of reports from
these sensors. it is set up like this:
pressure_sensor_records
belongs_to pressure_sensors
id, pressure_sensor_id, datetime, value
so i could have pressure_sensor has_many :pressure_sensor_reports
that part i think will not be a problem.

if you have read this far, thanks for your time.

does this challenge make sense?

thanks
sk

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs