Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Is it better to create 'duplicate' inverse join records or traverse via ruby/rails?

Databases • Asked by Thomas Bush

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

  1. 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.

  2. 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!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.