public function setUp() { $this->db = AetherDatabase::instance('test_mysql'); // Empty the test database if ($this->db->query('TRUNCATE TABLE test_database') === false) { throw new Exception('Could not truncate test_database'); } // Insert test rows to the db $this->fixture = array(array('Espen', 'Volden', 18), array('Espen', 'S', 25), array('Edda', 'Media', 110), array('Ompa', 'Lompa', 5)); foreach ($this->fixture as $row) { $sql = 'INSERT INTO test_database (first_name, sur_name, age)' . "VALUES ('{$row[0]}', '{$row[1]}', {$row[2]})"; if ($this->db->query($sql) === false) { throw new Exception('Cold not create fixture data'); } } }
/** * Prepares the model database connection, determines the table name, * and loads column information. * * @return void */ public function __initialize() { if (!is_object($this->db)) { // Get database instance $this->db = AetherDatabase::instance($this->db); } if (empty($this->tableName)) { // Table name is the same as the object name $this->tableName = $this->objectName; if ($this->tableNamesPlural === true) { // Make the table name plural $this->tableName = Inflector::plural($this->tableName); } } if (is_array($this->ignoredColumns)) { // Make the ignored columns mirrored = mirrored $this->ignoredColumns = array_combine($this->ignoredColumns, $this->ignoredColumns); } // Set column aliases and working table if ($this->columnAlias !== NULL && is_array($this->columnAlias) && !empty($this->columnAlias)) { $this->db->setColumnAlias($this->tableName, $this->columnAlias); $this->db->setWorkingTable($this->tableName); } // Its not possible to have an alias for the id and to set primaryKey to // be the column if ($this->db->aliasColumn($this->primaryKey, false) != $this->primaryKey) { throw new Exception('Its impossible to set the primaryKey to ' . 'something different then the alias'); } // Load column information $this->reloadColumns(); }