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' ])
has_one
  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