@@ -23,7 +23,7 @@ public function set_up($connection_name=null)
23
23
Venue::$ has_one = array ();
24
24
Employee::$ has_one = array (array ('position ' ));
25
25
Host::$ has_many = array (array ('events ' , 'order ' => 'id asc ' ));
26
-
26
+
27
27
foreach ($ this ->relationship_names as $ name )
28
28
{
29
29
if (preg_match ("/ $ name/ " , $ this ->getName (), $ match ))
@@ -80,7 +80,7 @@ public function test_has_many_basic()
80
80
{
81
81
$ this ->assert_default_has_many ($ this ->get_relationship ());
82
82
}
83
-
83
+
84
84
public function test_eager_load_with_empty_nested_includes ()
85
85
{
86
86
$ conditions ['include ' ] = array ('events ' =>array ());
@@ -107,7 +107,7 @@ public function test_gh_256_eager_loading_three_levels_deep()
107
107
108
108
$ this ->assertEquals ('Yeah Yeah Yeahs ' ,$ bill_events [0 ]->title );
109
109
}
110
-
110
+
111
111
/**
112
112
* @expectedException ActiveRecord\RelationshipException
113
113
*/
@@ -423,6 +423,23 @@ public function test_has_many_with_explicit_keys()
423
423
Author::$ has_many = array (array ('explicit_books ' , 'class_name ' => 'Book ' , 'primary_key ' => 'parent_author_id ' , 'foreign_key ' => 'secondary_author_id ' ));
424
424
$ author = Author::find (4 );
425
425
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
+
426
443
foreach ($ author ->explicit_books as $ book )
427
444
$ this ->assert_equals ($ book ->secondary_author_id , $ author ->parent_author_id );
428
445
0 commit comments