# Complex Relations / Avoid deletion of join model objects?

**URL:** <https://www.ruby-forum.com/t/complex-relations-avoid-deletion-of-join-model-objects/169933>\
**Category:** Rails\
**Created:** [June 10, 2009, 12:54pm UTC](https://www.ruby-forum.com/t/complex-relations-avoid-deletion-of-join-model-objects/169933 "2009-06-10T12:54:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felix\_SchSSS\_fer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ed8c4c/32.png) [@Felix\_SchSSS\_fer](https://www.ruby-forum.com/u/Felix_SchSSS_fer)\
**Post date:** [June 10, 2009, 12:54pm UTC](https://www.ruby-forum.com/t/complex-relations-avoid-deletion-of-join-model-objects/169933/1 "2009-06-10T12:54:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Felix\_SchSSS\_fer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ed8c4c/32.png) [@Felix\_SchSSS\_fer](https://www.ruby-forum.com/u/Felix_SchSSS_fer)\
**Post date:** [June 10, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/complex-relations-avoid-deletion-of-join-model-objects/169933/2 "2009-06-10T14:15:05Z")

</div>

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.
