Complex Relations / Avoid deletion of join model objects?

Hello,

I have two models Host and Check connected through a join model
CheckConfig with has_many :through relations both ways. I now have a
third model Result, objects of which I’d like to attach to a give
check of a given host. My idea would be to attach the Result model to
the CheckConfig model through a belongs_to, but that brings two
problems:

  • if an object from the join model is deleted and recreated with the
    same host_id and check_id, it still gets another id, which breaks the
    belongs_to relation. Is there an option to avoid deletion of the join
    model objects and only mark them as not active or something, so that I
    can retain the simple interface of the has_many :through relationship?
  • how would I have to configure the relationships to be able e.g. to
    call some_host.checks[1].results.last to get the last result for a
    give check of a given host?

I’m afraid that I won’t be able to tackle that one with the standard
built-ins, but I would be glad for any hints or help on how to best
configure rails for that.

Thanks,

Felix

Make the join model temporal if you never want to delete your Result
data.

class CheckConfig
host_id
check_id
start_date_time
end_date_time
other_data

where a null/nil end date indicates that the CheckConfig is current.
Rather than deleting the record, stamp the end_date_time.