Skip to content

Commit d2bed65

Browse files
committed
GH-55 fixed error with eager loading when record doesn't exist
1 parent c225942 commit d2bed65

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function find_by_sql($sql, $values=null, $readonly=false, $includes=null)
220220
$list[] = $model;
221221
}
222222

223-
if ($collect_attrs_for_includes)
223+
if ($collect_attrs_for_includes && !empty($list))
224224
$this->execute_eager_load($list, $attrs, $includes);
225225

226226
return $list;

test/RelationshipTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,5 +674,13 @@ public function test_gh_40_relationships_with_joins_aliases_table_name_in_condit
674674

675675
$this->assert_equals($event->id, $event->venue->id);
676676
}
677+
678+
/**
679+
* @expectedException ActiveRecord\RecordNotFound
680+
*/
681+
public function test_xxx()
682+
{
683+
Author::find(999999, array('include' => array('books')));
684+
}
677685
};
678-
?>
686+
?>

test/models/Author.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Author extends ActiveRecord\Model
44
static $pk = 'author_id';
55
static $has_one = array(array('awesome_person', 'foreign_key' => 'author_id', 'primary_key' => 'author_id'),
66
array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id'));
7-
static $has_many;
7+
static $has_many = array(array('books'));
88
static $belongs_to = array();
99
static $setters = array('password');
1010

@@ -19,4 +19,4 @@ public function set_name($value)
1919
$this->assign_attribute('name',$value);
2020
}
2121
};
22-
?>
22+
?>

0 commit comments

Comments
 (0)