Skip to content

Instantly share code, notes, and snippets.

@rsim
Created December 15, 2009 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsim/257324 to your computer and use it in GitHub Desktop.
Save rsim/257324 to your computer and use it in GitHub Desktop.
require "rubygems"
gem "activerecord", "= 2.3.5"
gem "activerecord-oracle_enhanced-adapter", "= 1.2.3"
require "active_record"
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection( :adapter => "oracle_enhanced",
:database => "orcl", :username => "hr", :password => "hr")
ActiveRecord::Base.connection.instance_eval do
create_table :policies, :force => true do |t|
t.string :name
end
create_table :vendors, :force => true do |t|
t.string :name
t.integer :policy_id
end
end
class Policy < ActiveRecord::Base
has_many :vendors
end
class Vendor < ActiveRecord::Base
belongs_to :policy
end
p1 = Policy.create(:name => 'Policy 1')
p2 = Policy.create(:name => 'Policy 2')
Vendor.create(:name => 'Vendor 1', :policy => p1)
Vendor.create(:name => 'Vendor 2', :policy => p1)
Vendor.create(:name => 'Vendor 3', :policy => p2)
Vendor.all(:include => [:policy]).each do |v|
v.policy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment