All threads / When to setup associations in Rails db?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

When to setup associations in Rails db?

Javid Freeman asked in Databases
I've always wondered if there is a better way to help database query performance in rails by breaking up tables with lots of columns? Any recommendations would be appreciated.

Does it make more sense to break out columns into another table or keep them in one?

Example: 

Client.name
Client.address
Client.city
Client.state
Client.zip
Client.twitter
Client.facebook
Client.instagram
Client.contact_name
Client.contact_phone
Client.contact_email
etc...

VS

Client.name

has_one :address
Client.address.address
Client.address.city
Client.address.state
Client.address.zip

has_one :social
Client.social.twitter
Client.social.facebook
Client.social.instagram

has_one :contact
Client.contact.name
Client.contact.phone
Client.contact.email


Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 38,558+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.