Last active
August 29, 2015 14:06
-
-
Save bruno-/babba3279f8d03be423e to your computer and use it in GitHub Desktop.
Using standalone ActiveRecord is really easy
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
require "active_record" | |
require "pg" | |
# AR connection | |
ActiveRecord::Base.establish_connection( | |
adapter: "postgresql", | |
database: "lynda_test", | |
username: "<db_username>", | |
password: "<db_password>", | |
host: "localhost", | |
port: "5432", | |
) | |
# models (tables have to exist in the DB) | |
class Customer < ActiveRecord::Base | |
has_many :sales | |
end | |
class Item < ActiveRecord::Base | |
has_many :sales | |
end | |
class Sale < ActiveRecord::Base | |
belongs_to :customer | |
belongs_to :item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment