Rails developers: avoid has_one

Complicated code with complicated edge cases
Less code with fewer edge cases
suppliers = Supplier.order(:id).limit(10)
supplier = Supplier.order(:id).limit(10).select(Supplier.column_names - [ 'big_column' ])
  1. ALTER TABLE [parent table] ADD [all columns in child table]
  2. UPDATE [parent table] SET [column1 of child table] = (SELECT column1 FROM [child table] WHERE [child table].[foreign key] = [parent table].id, …
  3. DROP TABLE [child table]




Journalist, ex software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam Hooper

Adam Hooper

Journalist, ex software engineer

More from Medium

Intro to Programming Paradigms

Seeding Data with Faker in Ruby

The logo for the Faker library

Advent of Code 2021 in Ruby Getting Started & Day 1

How to Implement Pagination in Rails