Created
June 26, 2013 07:51
-
-
Save Empact/5865555 to your computer and use it in GitHub Desktop.
This file contains 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
gem 'rails', '3.2.13' | |
require 'active_record' | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: ':memory:' | |
) | |
ActiveRecord::Schema.define do | |
create_table :firms, force: true do |t| | |
end | |
create_table :clients, force: true do |t| | |
t.integer :firm_id | |
t.string :description | |
end | |
end | |
class Firm < ActiveRecord::Base | |
has_many :clients | |
end | |
class Client < ActiveRecord::Base | |
belongs_to :firm | |
end | |
firm = Firm.new | |
firm.clients << Client.create! | |
firm.save! | |
puts "#{firm.clients.count} clients. 1 expected." | |
updated_clients = firm.clients.update_all(description: 'Great!') | |
puts "#{updated_clients} clients updated. 1 expected." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment