Skip to content

Instantly share code, notes, and snippets.

@adamhooper
Last active April 1, 2016 15:05
Show Gist options
  • Save adamhooper/3ebdb6f026c034253d060db726f7fafb to your computer and use it in GitHub Desktop.
Save adamhooper/3ebdb6f026c034253d060db726f7fafb to your computer and use it in GitHub Desktop.
Active Record has_one is usually bad
class Account < ActiveRecord::Base
belongs_to :supplier
end
class Supplier < ActiveRecord::Base
has_one :account
end
class CreateSuppliers < ActiveRecord::Migration
def change
create_table :suppliers do |t|
t.string :name
t.timestamps null: false
end
create_table :accounts do |t|
t.integer :supplier_id
t.string :account_number
t.timestamps null: false
end
add_index :accounts, :supplier_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment