I have following tables in database
Main Table :
CREATE TABLE IF NOT EXISTS `exam` (
`eid` int(11) unsigned NOT NULL,
PRIMARY KEY (`eid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Translation Table:
CREATE TABLE IF NOT EXISTS `exam_translation` (
`etid` int(11) unsigned NOT NULL,
`lang` char(2) NOT NULL,
`title` varchar(1000) DEFAULT NULL,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
PRIMARY KEY (`etid`,`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I have following Main Base Model at (APPLICATION_PATH/models/base):
class Model_Base_Exam extends Doctrine_Record {
public function setTableDefinition() {
$this->setTableName('exam');
$this->option('type', 'INNODB');
$this->option('charset', 'utf8');
$this->option('collate', 'utf8_general_ci');
$this->hasColumn('eid', 'integer', 11, array(
'primary' => true,
'unsigned' => true,
'notnull' => true,
));
$this->hasColumn('title', 'string', 1000);
}
public function setUp(){
$this->hasMany('Model_Answer', array(
'local' => 'eid',
'foreign' => 'examid',
'onUpdate' => 'CASCADE',
'onDelete' => 'RESTRICT',
));
$this->hasMany('Model_ExamTranslation', array(
'local' => 'eid',
'foreign' => 'etid',
));
$this->actAs('I18n', array(
'fields' => array('title'),
'className' => 'Model_ExamTranslation',
));
}
}
I have following Main Model at (APPLICATION_PATH/models/):
class Model_Exam extends Model_Base_Exam {
public static function findAll(){
return Doctrine_Query::CREATE()->from('Model_Exam e')->execute();
}
private function lastInsertId($model, $field){
return $sql = Doctrine_Query::create()
->select('MAX(e.'.$field.') as mid')
->from($model.' e')
->execute();
}
public static function getNewId($model, $field){
$maxId = self::lastInsertId($model, $field);
return $maxId[0]->mid+1;
}
public static function addNewRecord($title){
$exam = new Model_Exam();
$examTranslation = new Model_ExamTranslation();
echo $exam->eid = self::getNewId('Model_Exam', 'eid'); echo '<br>';
echo $examTranslation->etid = self::getNewId('Model_ExamTranslation', 'etid');
$exam->save();
}
}
I have following Main Base Translation Model at (APPLICATION_PATH/models/Base/):
class Model_Base_ExamTranslation extends Doctrine_Record {
public function setTableDefinition(){
$this->setTableName('exam_translation');
$this->option('type', 'INNODB');
$this->option('charset', 'utf8');
$this->option('collate', 'utf8_general_ci');
$this->hasColumn('etid', 'integer', 11, array(
'primary' => false,
'unsigned' => true,
'notnull' => true,
));
$this->hasColumn('lang', 'string', 2, array(
'primary' => false,
'notnull' => true,
));
$this->hasColumn('title', 'string', 1000);
$this->hasColumn('created', 'Timestamp');
$this->hasColumn('updated', 'Timestamp');
}
public function setUp(){
$this->actAs('Timestampable', array(
'created' => array(
'name' => 'created',
),
'updated' => array(
'name' => 'updated'
),
));
}
}
I have following Main Translation Model at (APPLICATION_PATH/models/):
class Model_ExamTranslation extends Model_Base_ExamTranslation {
}
Iam new to ZF and Doctrine, so unable to get Doctrine’s I18n running smoothly.
Iam unable to apply following lines in Doctrine’s manual. http://www.doctrine-project.org/projects/orm/1.2/docs/manual/behaviors/en#core-behaviors:i18n
Following are lines from manual, which are making me confused.
Now the first time you initialize a new NewsItem record Doctrine initializes the behavior that builds the followings things:
1. Record class called NewsItemTranslation
2. Bi-directional relations between NewsItemTranslation and NewsItem
Can some one guide me where Iam doing wrong and how it can be rectified.
Thanks in advance