<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -374,11 +374,12 @@ module DBI
   #   class Post &lt; DBI::Model( :posts ); end
   # You can specify the primary key column(s) using an array, like so:
   #   class Author &lt; DBI::Model( :authors, [ 'auth_num' ] ); end
-  def self.Model( table, pk_ = [ 'id' ] )
-    h = DBI::DatabaseHandle.last_handle
+  def self.Model( table, options = Hash.new )
+    h = options[ :dbh ] || DBI::DatabaseHandle.last_handle
     if h.nil? or not h.connected?
       raise DBI::Error.new( &quot;Attempted to create a Model class without first connecting to a database.&quot; )
     end
+    pk_ = options[ :pk ] || [ 'id' ]
     if not pk_.respond_to? :each
       raise DBI::Error.new( &quot;Primary key must be enumerable (was given #{pk_.inspect})&quot; )
     end</diff>
      <filename>lib/m4dbi/model.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,8 +34,8 @@ describe 'A DBI::Model subclass' do
     @m_post = Class.new( DBI::Model( :posts ) )
     @m_empty = Class.new( DBI::Model( :empty_table ) )
     @m_mc = Class.new( DBI::Model( :many_col_table ) )
-    @m_nipk = Class.new( DBI::Model( :non_id_pk, [ :str ] ) )
-    @m_mcpk = Class.new( DBI::Model( :mcpk, [ :kc1, :kc2 ] ) )
+    @m_nipk = Class.new( DBI::Model( :non_id_pk, :pk =&gt; [ :str ] ) )
+    @m_mcpk = Class.new( DBI::Model( :mcpk, :pk =&gt; [ :kc1, :kc2 ] ) )
     class Author &lt; DBI::Model( :authors ); end
   end
 
@@ -90,6 +90,7 @@ describe 'A DBI::Model subclass' do
       reset_data( dbh, &quot;test-data2.sql&quot; )
 
       @m_author2 = Class.new( DBI::Model( :authors ) )
+      @m_author2.dbh.should.equal dbh
 
       @m_author2[ 1 ].should.be.nil
       a11 = @m_author2[ 11 ]
@@ -101,7 +102,34 @@ describe 'A DBI::Model subclass' do
       a2.name.should.equal 'author2'
     ensure
       # Clean up handles for later specs
-      dbh.disconnect if dbh and dbh.connected?
+      # puts dbh.object_id
+      # dbh.disconnect if dbh and dbh.connected?
+      connect_to_spec_database
+    end
+  end
+
+  it 'can use a specific database handle' do
+    begin
+      dbh1 = connect_to_spec_database
+      dbh1.should.equal DBI::DatabaseHandle.last_handle
+      dbh2 = connect_to_spec_database( ENV[ 'M4DBI_DATABASE2' ] || 'm4dbi2' )
+      dbh2.should.equal DBI::DatabaseHandle.last_handle
+      reset_data( dbh2, &quot;test-data2.sql&quot; )
+
+      dbh1.should.not.equal dbh2
+
+      class Author1 &lt; DBI::Model( :authors, :dbh =&gt; dbh1 ); end
+      class Author2 &lt; DBI::Model( :authors, :dbh =&gt; dbh2 ); end
+
+      a1 = Author1[ 1 ]
+      a1.should.not.be.nil
+      a1.name.should.equal 'author1'
+
+      a11 = Author2[ 11 ]
+      a11.should.not.be.nil
+      a11.name.should.equal 'author11'
+    ensure
+      # Clean up handles for later specs
       connect_to_spec_database
     end
   end
@@ -674,8 +702,8 @@ describe 'A found DBI::Model subclass instance' do
     @m_author = Class.new( DBI::Model( :authors ) )
     @m_post = Class.new( DBI::Model( :posts ) )
     @m_mc = Class.new( DBI::Model( :many_col_table ) )
-    @m_nipk = Class.new( DBI::Model( :non_id_pk, [ :str ] ) )
-    @m_mcpk = Class.new( DBI::Model( :mcpk, [ :kc1, :kc2 ] ) )
+    @m_nipk = Class.new( DBI::Model( :non_id_pk, :pk =&gt; [ :str ] ) )
+    @m_mcpk = Class.new( DBI::Model( :mcpk, :pk =&gt; [ :kc1, :kc2 ] ) )
   end
 
   it 'provides access to primary key value' do</diff>
      <filename>spec/model.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>42bb4ef9a2cead8884cb0dca3a43f0d149e264e5</id>
    </parent>
  </parents>
  <author>
    <name>Pistos</name>
    <email>gitsomegrace.5.pistos@geoshell.com</email>
  </author>
  <url>http://github.com/Pistos/m4dbi/commit/60c5f69c5443b66128a75c668247e28482de5a87</url>
  <id>60c5f69c5443b66128a75c668247e28482de5a87</id>
  <committed-date>2009-04-20T11:15:10-07:00</committed-date>
  <authored-date>2009-04-20T11:15:10-07:00</authored-date>
  <message>Changed Model subclass/creation syntax to take an options hash instead of only primary key array.
Options: :dbh and :pk.
Model can now be explicitly associated with a specific DBI handle.</message>
  <tree>1b36cc6b28cb22e98abcb98e21622d8cfbee35f1</tree>
  <committer>
    <name>Pistos</name>
    <email>gitsomegrace.5.pistos@geoshell.com</email>
  </committer>
</commit>
