gabordemooij/redbean — Issue #112: RedBean_SimpleModel Models not calling formatBeanTable()
Author: abxccd
Created: 2011-11-29 23:31:33+00:00
State: open

This issue appears in the latest 2.2.3 as well as the latest 3.0 master:

Formatter:

class MyFormatter extends RedBean_DefaultBeanFormatter {

public function formatBeanTable($type){
var_dump($type); //For testing whether formatBeanTable is called or not (never called by models)
return $this->tablePrefixStr . 'T' . strtolower($type);
}
}

ModelFormatter:

class MyModelFormatter implements RedBean_IModelFormatter {

public function formatModel($model) {
return $model;
}

}

Model:
class User extends RedBean_SimpleModel{

public function bark(){
echo "woof";
}
}

Test Code:
$formatter = new MyFormatter();
$formatter->setPrefix("v1_");
R::$writer->setBeanFormatter($formatter);

$test1 = R::dispense('User');
$test1->bark(); //echos woof
echo $test1->getMeta('type'); //echos User
$test1->test = 'asdf';

R::store($test1); //Fails: Table 'v1_User` not found! The table name should be `v1_Tuser`