Skip to content

Instantly share code, notes, and snippets.

@tanordheim
Created March 29, 2010 15:19
Show Gist options
  • Save tanordheim/347945 to your computer and use it in GitHub Desktop.
Save tanordheim/347945 to your computer and use it in GitHub Desktop.
class ChildModelOne extends ParentModel {
}
class ChildModelTwo extends ParentModel {
}
// Rig up Doctrine auto loader
spl_autoload_register(array("Doctrine", "autoload"));
spl_autoload_register(array("Doctrine_Core", "modelsAutoload"));
// Instantiate a manager instance and connection
$_DOCTRINE_MANAGER = Doctrine_Manager::getInstance();
$_DOCTRINE_CONNECTION = Doctrine_Manager::connection("mysql://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST . "/" . DB_NAME);
// Configure Doctrine
$_DOCTRINE_MANAGER->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$_DOCTRINE_MANAGER->setAttribute(Doctrine_Core::ATTR_EXPORT, Doctrine_Core::EXPORT_ALL);
$_DOCTRINE_MANAGER->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
$_DOCTRINE_MANAGER->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$_DOCTRINE_MANAGER->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
// Enable model auto loading
Doctrine_Core::loadModels(APP_DIR . "/models");
// Generate a YAML schema of the models
Doctrine_Core::generateYamlFromModels(APP_DIR . "/schema/schema.yml", APP_DIR . "/models");
class ParentModel extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("test", "integer");
$this->setSubclasses(array(
"ChildModelOne" => array("type" => 1),
"ChildModelTwo" => array("type" => 2)
));
}
}
Parent:
connection: 0
tableName: parent
columns:
id:
type: integer(8)
autoincrement: true
primary: true
test: integer(8)
ChildModelOne:
connection: 0
tableName: child_model_one
columns:
id:
type: integer(8)
autoincrement: true
primary: true
test: integer(8)
ChildModelTwo:
connection: 0
tableName: child_model_two
columns:
id:
type: integer(8)
primary: true
test: integer(8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment