I am buidling an application for real estate centered around comparing properties. I have a self referential relationship, Comps, which joins two properties and stores some additional data.
PropertyA.comps => PropertyB
The following must also be true:
PropertyB.comps => PropertyA
I can only think of two routes to accomplish included below
Add create and destroy hooks to automatically add and removed the inverse relationship. When researching, I found a great article on this method. My only reservation is that creating duplicate records and using hooks feels dirty, but my hunch is that this is an exception.
Handle this case with ruby. Load up all the normal and inverse Comp records, normalize and merge. This approach feels like it would be very slow in comparion.
I was hoping that someone with more experience could validate my assumption that option 1 is the optimal direction to move. It feels like an exception to the rule: that using hooks and creating duplicate records makes sense in this case. I appreciate any help or advice you can provide, thanks!
Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.