. */ /** * Doctrine_Ticket_912_TestCase * * @package Doctrine * @author David Stendardi * @category Object Relational Mapping * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ */ class Doctrine_Ticket_912_TestCase extends Doctrine_UnitTestCase { /** * prepareData */ public function prepareData() { $oResume = new ticket912_Resume; $oResume->title = 'titre'; $oResume->Person->name = 'David'; $oResume->KnownLanguages[0]->comments = 'foo'; $oResume->KnownLanguages[0]->Language->label = "Enlish"; $oResume->KnownLanguages[0]->Level->label = "Fluent"; $oResume->save(); } /** * prepareTables */ public function prepareTables() { $this->tables = array(); $this->tables[] = 'ticket912_Resume'; $this->tables[] = 'ticket912_Person'; $this->tables[] = 'ticket912_ResumeHasLanguage'; $this->tables[] = 'ticket912_LanguageLevel'; $this->tables[] = 'ticket912_Language'; parent :: prepareTables(); } /** * Test the existence expected indexes */ public function testTicket() { $q = new Doctrine_Query(); // simple query with deep relations $q->addSelect('Resume.id, Person.id, Person.name, KnownLanguages.id, Level.label, Language.label') ->from('ticket912_Resume Resume') ->leftJoin('Resume.Person Person') ->leftJoin('Resume.KnownLanguages KnownLanguages') ->leftJoin('KnownLanguages.Level Level') ->leftJoin('KnownLanguages.Language Language'); $aResult = $q->fetchArray(); // should be setted.. $issetLevel = isset($aResult[0]['KnownLanguages'][0]['Level']); $issetLanguage = isset($aResult[0]['KnownLanguages'][0]['Language']); $this->assertTrue($issetLevel); $this->assertTrue($issetLanguage); } } /** * This class has been auto-generated by the Doctrine ORM Framework */ class ticket912_Resume extends Doctrine_Record { public static function initMetadata($mapping) { $mapping->setTableName('resume'); $mapping->mapColumn('id', 'integer', 8, array ( 'primary' => true, 'autoincrement' => true, 'unsigned' => true, )); $mapping->mapColumn('person_id', 'integer', 8, array('unsigned' => true)); $mapping->mapColumn('title', 'string', 255); $mapping->hasMany('ticket912_ResumeHasLanguage as KnownLanguages', array('local' => 'id', 'foreign' => 'resume_id')); $mapping->hasOne('ticket912_Person as Person', array( 'local' => 'person_id', 'foreign' => 'id', 'onDelete' => 'SET NULL', 'onUpdate' => 'CASCADE' )); } } /** * First level one to one relation class Language */ class ticket912_Person extends Doctrine_Record { public static function initMetadata($mapping) { $mapping->setTableName('person'); $mapping->mapColumn('id', 'integer', 8, array ( 'primary' => true, 'autoincrement' => true, 'unsigned' => true, )); $mapping->mapColumn('name', 'string', 255, array ()); } } /** * Second level one to many relation class ResumeHasLanguageLanguage */ class ticket912_ResumeHasLanguage extends Doctrine_Record { public static function initMetadata($mapping) { $mapping->setTableName('resume_has_language'); $mapping->mapColumn('id', 'integer', 8, array ( 'primary' => true, 'autoincrement' => true, 'unsigned' => true, )); $mapping->mapColumn('resume_id', 'integer', 8, array ( 'notnull' => true, 'unsigned' => true, )); $mapping->mapColumn('language_id', 'integer', 2, array ( 'unsigned' => true, )); $mapping->mapColumn('language_level_id', 'integer', 2, array ( 'unsigned' => true, )); $mapping->mapColumn('comments', 'string', 4000, array ()); $mapping->hasOne('ticket912_Resume as Resume', array('local' => 'resume_id', 'foreign' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); $mapping->hasOne('ticket912_Language as Language', array('local' => 'language_id', 'foreign' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')); $mapping->hasOne('ticket912_LanguageLevel as Level', array('local' => 'language_level_id', 'foreign' => 'id', 'onDelete' => 'SET NULL', 'onUpdate' => 'CASCADE')); } } /** * Third level one to one relation class Language */ class ticket912_Language extends Doctrine_Record { public static function initMetadata($mapping) { $mapping->setTableName('language'); $mapping->mapColumn('id', 'integer', 2, array( 'primary' => true, 'autoincrement' => true, 'unsigned' => true, )); $mapping->mapColumn('label', 'string', 100, array ('notnull' => true)); $mapping->hasMany('ticket912_Resume as Resumes', array('local' => 'id', 'foreign' => 'language_id')); $mapping->hasMany('ticket912_ResumeHasLanguage as ResumeKnownLanguages', array('local' => 'id', 'foreign' => 'language_id')); } } /** * Third level one to one relation class Language */ class ticket912_LanguageLevel extends Doctrine_Record { public static function initMetadata($mapping) { $mapping->setTableName('language_level'); $mapping->mapColumn('id', 'integer', 2, array ( 'primary' => true, 'autoincrement' => true, 'unsigned' => true, )); $mapping->mapColumn('label', 'string', 100, array ('notnull' => true)); $mapping->hasMany('ticket912_ResumeHasLanguage as ResumeKnownLanguages', array( 'local' => 'id', 'foreign' => 'language_level_id')); } }