Conditional relationships (?) #890
-
Dear all, I would like to write a gateway that read a signal from a sensor using a supported protocol and send the read value using other different protocols. I tried three different approaches:
Do you see better options? Based on your experience which one it seems better to you? Dynamically
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think your suggested solutions make sense. To me, the options which I like the most are probably: Nullable foreign keysHaving a bunch of nullable foreign keys, and you assign the relevant one. The downside is you end up with lots of foreign keys if you have a lot of protocols, but not the end of the world. You have a single protocol table, with JSON dataJust as you suggested in your last approach. It means you can a single foreign key, and store the information about the particular protocol in a JSON field. A small hint - use |
Beta Was this translation helpful? Give feedback.
I think your suggested solutions make sense.
To me, the options which I like the most are probably:
Nullable foreign keys
Having a bunch of nullable foreign keys, and you assign the relevant one. The downside is you end up with lots of foreign keys if you have a lot of protocols, but not the end of the world.
You have a single protocol table, with JSON data
Just as you suggested in your last approach. It means you can a single foreign key, and store the information about the particular protocol in a JSON field.
A small hint - use
JSONB
instead ofJSON
if possible, it's better for querying that plainJSON
.