summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-20 10:23:04 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-20 10:23:04 +0100
commitacb40d091fc096674b12ab3c95cabf49a42172c9 (patch)
tree0af3a35a628dc28c15eacfa22f1a1bd86bf9f764
parent1d43634ebd97cf67e2ba27f1880cc59b86b29f96 (diff)
correctly map table column names to properties
-rw-r--r--db/entity.php3
-rw-r--r--tests/db/EntityTest.php6
2 files changed, 5 insertions, 4 deletions
diff --git a/db/entity.php b/db/entity.php
index 2c6f4f899..5654e1b80 100644
--- a/db/entity.php
+++ b/db/entity.php
@@ -121,7 +121,8 @@ abstract class Entity {
*/
public function fromRow(array $row){
foreach($row as $key => $value){
- $this->$key = $value;
+ $prop = $this->columnToProperty($key);
+ $this->$prop = $value;
}
}
diff --git a/tests/db/EntityTest.php b/tests/db/EntityTest.php
index 44f288a04..793ca8ded 100644
--- a/tests/db/EntityTest.php
+++ b/tests/db/EntityTest.php
@@ -43,15 +43,15 @@ class EntityTest extends \PHPUnit_Framework_TestCase {
public function testFromRow(){
$row = array(
- 'name' => 'john',
+ 'pre_name' => 'john',
'email' => 'john@something.com'
);
$entity = new TestEntity();
$entity->fromRow($row);
- $this->assertEquals($row['name'], $entity->name);
- $this->assertEquals($row['email'], $entity->email);
+ $this->assertEquals($row['pre_name'], $entity->getPreName());
+ $this->assertEquals($row['email'], $entity->getEmail());
}