Wondering if anybody could give me a hand. I have three tables,
operators, operator_aps, and pingable_ips with the following
operator has_many operator_aps
operator has_many pingable_ips
Now, what I need to do is relate one of the operator's pingable_ips
with each of their operator_aps. I'm not sure what the best way to go
about this is, or how to properly define it with the has_many/
belongs_to relationships. I was thinking of just doing:
operator_ap has_one pingable_ip
but then pingable_ip belongs_to both operator and operator_ap, and
operator_ap already belongs_to an operator. Not sure if this will
cause any issues, especially when deleting records from these tables.
I think it depends on the relationship between pingable_aps and
pingable_ips. If you allocate the ip to the app depending on
whether it is one of the operator's ip addresses, then break the
association between the operator and the app. You can always tell
the ip address to do things to the apps it owns. Otherwise, if you
allocate the ap depending on whether it is going to the operator's
app, break the association between the operator and the ip.
Basically, they should not be poking in each other's pockets so
much. If it is one ip per app, you can always ask the apps to
handle the IP issues.
As a third choice, the operator keeps the mapping between
her apps and her ips, and the two need never know about this
Circular graphs make recursion too ... er, interesting...
If anybody has any advice on a nice way to set these relationships up,
it would be greatly appreciated.
HTH, though I don't understand your problem domain in detail.