@@ -23,7 +23,7 @@ public function set_up($connection_name=null)
2323 Venue::$ has_one = array ();
2424 Employee::$ has_one = array (array ('position ' ));
2525 Host::$ has_many = array (array ('events ' , 'order ' => 'id asc ' ));
26-
26+
2727 foreach ($ this ->relationship_names as $ name )
2828 {
2929 if (preg_match ("/ $ name/ " , $ this ->getName (), $ match ))
@@ -80,7 +80,7 @@ public function test_has_many_basic()
8080 {
8181 $ this ->assert_default_has_many ($ this ->get_relationship ());
8282 }
83-
83+
8484 public function test_eager_load_with_empty_nested_includes ()
8585 {
8686 $ conditions ['include ' ] = array ('events ' =>array ());
@@ -107,7 +107,7 @@ public function test_gh_256_eager_loading_three_levels_deep()
107107
108108 $ this ->assertEquals ('Yeah Yeah Yeahs ' ,$ bill_events [0 ]->title );
109109 }
110-
110+
111111 /**
112112 * @expectedException ActiveRecord\RelationshipException
113113 */
@@ -423,6 +423,23 @@ public function test_has_many_with_explicit_keys()
423423 Author::$ has_many = array (array ('explicit_books ' , 'class_name ' => 'Book ' , 'primary_key ' => 'parent_author_id ' , 'foreign_key ' => 'secondary_author_id ' ));
424424 $ author = Author::find (4 );
425425
426+ $ this ->assert_equals (2 , count ($ author ->explicit_books ));
427+
428+ foreach ($ author ->explicit_books as $ book )
429+ $ this ->assert_equals ($ book ->secondary_author_id , $ author ->parent_author_id );
430+
431+ $ this ->assert_true (strpos (ActiveRecord \Table::load ('Book ' )->last_sql , "secondary_author_id " ) !== false );
432+ Author::$ has_many = $ old ;
433+ }
434+
435+ public function test_has_many_with_explicit_keys_and_eager_loading ()
436+ {
437+ $ old = Author::$ has_many ;
438+ Author::$ has_many = array (array ('explicit_books ' , 'class_name ' => 'Book ' , 'primary_key ' => 'parent_author_id ' , 'foreign_key ' => 'secondary_author_id ' ));
439+ $ author = Author::find (4 , array ('include ' => 'explicit_books ' ));
440+
441+ $ this ->assert_equals (2 , count ($ author ->explicit_books ));
442+
426443 foreach ($ author ->explicit_books as $ book )
427444 $ this ->assert_equals ($ book ->secondary_author_id , $ author ->parent_author_id );
428445
0 commit comments