开发者

Doctrine: hasOne gives errors

when I am trying to give a relationship to user->group I get an error here is my code

<?php
class User extends Doctrine_Record {

    public function setTableDefinition() {
        $this->hasColumn('username', 'string', 255, array('unique' => 'true'));
        $this->hasColumn('password', 'string', 255);
        $this->hasColumn('email', 'string', 255, array('unique' => 'true'));
        $this->hasColumn('group_id', 'integer', 20);
    }

    public function setUp() {
        $this->setTableName('users');
        $this->actAs('Timestampable');
        $this->hasMutator('password', '_encrypt_password');

        $this->hasOne('Group', a开发者_JAVA百科rray(
            'local' => 'group_id',
            'foreign' => 'id'
            ));
    }

    protected function _encrypt_password($value) {
        $salt = '#*seCrEt!@-*%';
        $this->_set('password', md5($salt . $value));
    }
}
?>

Can someone please explain why I'm getting errors?

here is my group code:

<?php
class Group extends Doctrine_Record {

    public function setTableDefinition() {
        $this->hasColumn('name', 'string', 255);
    }

    public function setUp() {
        $this->setTableName('groups');
    }

}
?>

I'm running on Code Igniter 1.7.2 and Doctrine 1.2.2


Old question but no anwser... I had some problems with this myself and the problem was this

$this->hasColumn('group_id', 'integer', 20);

For me the default doctrine settings was 4 and It always gave me errors unless i changes the int for the relation

So if the default is 4 in doctrine I had to use $this->hasColumn('group_id', 'integer', 4);

Note: I'm also using Codeigniter 1.7.2 + Doctrine (but 1.2.1) and It looks like your trying out the same tutorial as I was.

Just a note to checkout if having problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜