so the module im working on is an instant messaging module (it was working well before re-doing it with doctrine)
so for my Doctrine Records i have
Users
messages
a user has many messages as sent messages
a user also has many messages as recd messages
id like it such that if a user sends a message to another user, the sender has that message as a sent message and the recvr has it as a recd message. id just like people to point out all my mistakes and discuss/debate the best way to accomplishing my goals.
kyle
here are my models
Code
class Zim_Model_User extends Doctrine_Record
{
/**
* Set table definition.
*
* @return void
*/
public function setTableDefinition()
{
$this->setTableName('zim_users');
$this->hasColumn('uid', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('status', 'integer', null, array(
'notnull' => true,
'default' => 0,
));
$this->hasColumn('uname', 'string', 100, array(
'notnull' => true,
'default' => '',
));
}
/**
* Record setup.
*
* @return void
*/
public function setUp()
{
$this->actAs('Timestampable');
$this->hasMany('Zim_Model_Message as SentMessages', array(
'local' => 'msg_to',
'foreign' => 'msg_from',
'refClass' => 'Zim_Model_UserMessage'
)
);
$this->hasMany('Zim_Model_Message as RecdMessages', array(
'local' => 'msg_from',
'foreign' => 'msg_to',
'refClass' => 'Zim_Model_UserMessage'
)
);
}
{
/**
* Set table definition.
*
* @return void
*/
public function setTableDefinition()
{
$this->setTableName('zim_users');
$this->hasColumn('uid', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('status', 'integer', null, array(
'notnull' => true,
'default' => 0,
));
$this->hasColumn('uname', 'string', 100, array(
'notnull' => true,
'default' => '',
));
}
/**
* Record setup.
*
* @return void
*/
public function setUp()
{
$this->actAs('Timestampable');
$this->hasMany('Zim_Model_Message as SentMessages', array(
'local' => 'msg_to',
'foreign' => 'msg_from',
'refClass' => 'Zim_Model_UserMessage'
)
);
$this->hasMany('Zim_Model_Message as RecdMessages', array(
'local' => 'msg_from',
'foreign' => 'msg_to',
'refClass' => 'Zim_Model_UserMessage'
)
);
}
Code
<?php
class Zim_Model_Message extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('zim_message');
$this->hasColumn('mid', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('msg_to', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'autoincrement' => false
));
$this->hasColumn('msg_from', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'autoincrement' => false,
));
$this->hasColumn('message', 'clob', array(
'unique' => false,
'primary'=> false,
'notnull' => true,
'default' => ''
));
$this->hasColumn('recd', 'integer',2 , array(
'unique' => false,
'primary'=> false,
'notnull' => true,
'default' => 0
));
}
public function setUp()
{
$this->actAs('Timestampable');
$this->hasOne('Zim_Model_User as to', array(
'local' => 'msg_to',
'foreign' => 'msg_from',
'refClass' => 'Zim_Model_UserMessage'
)
);
$this->hasOne('Zim_Model_User as from', array(
'local' => 'msg_from',
'foreign' => 'msg_to',
'refClass'=> 'Zim_Model_UserMessage'
)
);
}
}
class Zim_Model_Message extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('zim_message');
$this->hasColumn('mid', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('msg_to', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'autoincrement' => false
));
$this->hasColumn('msg_from', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'autoincrement' => false,
));
$this->hasColumn('message', 'clob', array(
'unique' => false,
'primary'=> false,
'notnull' => true,
'default' => ''
));
$this->hasColumn('recd', 'integer',2 , array(
'unique' => false,
'primary'=> false,
'notnull' => true,
'default' => 0
));
}
public function setUp()
{
$this->actAs('Timestampable');
$this->hasOne('Zim_Model_User as to', array(
'local' => 'msg_to',
'foreign' => 'msg_from',
'refClass' => 'Zim_Model_UserMessage'
)
);
$this->hasOne('Zim_Model_User as from', array(
'local' => 'msg_from',
'foreign' => 'msg_to',
'refClass'=> 'Zim_Model_UserMessage'
)
);
}
}
Code
class Zim_Model_UserMessage extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('msg_to', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
));
$this->hasColumn('msg_from', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
));
}
}
{
public function setTableDefinition()
{
$this->hasColumn('msg_to', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
));
$this->hasColumn('msg_from', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
));
}
}
