Permalink
Browse files

You can now do something like Object::find(123);

  • Loading branch information...
kyledecot committed May 11, 2012
1 parent 0ac183b commit fdc425471989c6b80702bb81fedf225c82222cf6
Showing with 14 additions and 1 deletion.
  1. +9 −1 db_object.php
  2. +5 −0 test/DbObjectTest.php
View
@@ -1136,7 +1136,15 @@ public static function find($columns, $table='') {
if (!$object->null_instantiated) {
throw new Exception("The method: 'find' cannot be called on an existing object, it must be null instantiated.");
}
-
+
+ // Column can either be an array OR it can simply
+ // be the ID of the object we're looking for...
+
+ if (!is_array($columns)) {
+ $primary_key = $object->primary_key_field;
+ $columns = array($primary_key => (int)$columns);
+ }
+
foreach ($columns as $field_name => $field_value) {
// Make sure it's a legit attribute
if (!$object->is_acceptable_attribute($field_name)) {
View
@@ -883,6 +883,11 @@ function testFindWhenUsedNormally()
$animal = db_object::find(array('name' => 'Cow'), 'animals');
$this->assertEquals(2, $animal->get_id());
}
+
+ function testFindUsingId() {
+ $farm = farm::find(1);
+ $this->assertEquals(1, $farm->get_id());
+ }
function testExtendedFind() {
$farm = farm::find(array('name' => 'eSchool Farms'));

0 comments on commit fdc4254

Please sign in to comment.