Last active
April 1, 2016 15:05
-
-
Save adamhooper/3ebdb6f026c034253d060db726f7fafb to your computer and use it in GitHub Desktop.
Active Record has_one is usually bad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Account < ActiveRecord::Base | |
belongs_to :supplier | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Supplier < ActiveRecord::Base | |
has_one :account | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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