Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 行为主义的问题_Php_Orm_Doctrine_Behavior - Fatal编程技术网

Php 行为主义的问题

Php 行为主义的问题,php,orm,doctrine,behavior,Php,Orm,Doctrine,Behavior,我在我的一个项目中遇到了一个问题,我把条令作为ORM使用 出于某种原因,在重建模型和数据库结构时,Doctrine忽略了行为和关系,我在一个表定义中定义了这些行为和关系。YAML表定义如下所示: ... User: actAs: Timestampable: Sluggable: unique: true fields: username canUpdate: true columns: id: type: i

我在我的一个项目中遇到了一个问题,我把条令作为ORM使用

出于某种原因,在重建模型和数据库结构时,Doctrine忽略了行为和关系,我在一个表定义中定义了这些行为和关系。YAML表定义如下所示:

...

User:  
  actAs:
    Timestampable:
    Sluggable:
      unique: true
      fields: username
      canUpdate: true
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    company_id
      type: integer(4)
    timezone_id:
      type: integer(1)
    role_id:
      type: integer(1)
    email:
      type: string(255)
    username:
      type: string(255)
      unique: true
    password:
      type: string(40)
    firstname:
      type: string(255)
    lastname:
      type: string(255)
    last_login:
      type: datetime
  relations:
    Company:
      local: company_id
      foreign: id
    Timezone:
      local: timezone_id
      foreign: id
    Role:
      local: role_id
      foreign: id

...
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` int(11) DEFAULT NULL,
  `timezone_id` tinyint(4) DEFAULT NULL,
  `role_id` tinyint(4) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(40) DEFAULT NULL,
  `firstname` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  `last_login` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
生成的表结构如下所示:

...

User:  
  actAs:
    Timestampable:
    Sluggable:
      unique: true
      fields: username
      canUpdate: true
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    company_id
      type: integer(4)
    timezone_id:
      type: integer(1)
    role_id:
      type: integer(1)
    email:
      type: string(255)
    username:
      type: string(255)
      unique: true
    password:
      type: string(40)
    firstname:
      type: string(255)
    lastname:
      type: string(255)
    last_login:
      type: datetime
  relations:
    Company:
      local: company_id
      foreign: id
    Timezone:
      local: timezone_id
      foreign: id
    Role:
      local: role_id
      foreign: id

...
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_id` int(11) DEFAULT NULL,
  `timezone_id` tinyint(4) DEFAULT NULL,
  `role_id` tinyint(4) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(40) DEFAULT NULL,
  `firstname` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  `last_login` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
正如你所看到的,条令生成了我定义的所有列,但由于某种原因,所有应该自动发生的事情都没有完成。首先,它不会在处为时间标记行为创建
updated\u列和在
处创建的
created\u列,也会丢失可标记行为的
slug

索引和外键约束也丢失

当我打开生成的模型类时,它看起来很好:

class BaseUser extends Doctrine_Record
{

    ....

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Company', array(
             'local' => 'company_id',
             'foreign' => 'id'));

        $this->hasOne('Timezone', array(
             'local' => 'timezone_id',
             'foreign' => 'id'));

        $this->hasOne('Role', array(
             'local' => 'role_id',
             'foreign' => 'id'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $sluggable0 = new Doctrine_Template_Sluggable(array(
             'unique' => true,
             'fields' => 'username',
             'canUpdate' => true,
        ));
        $this->actAs($timestampable0);
        $this->actAs($sluggable0);
    }

    ....

}
所以,问题在于SQL查询生成


有没有其他人遇到过类似的问题,或者您能在我的YAML定义中发现任何错误?

根据您发布的内容和随后的评论,您的
用户
表和
mysql
用户
表似乎存在名称冲突。正如您在将表重命名为
Person
时提到的,它按预期工作


根据我的经验,我总是在我的表中添加一个任意的表前缀,以避免这些类型的意外行为。

根据您发布的内容和随后的评论,您的
用户
表和
mysql
用户
表似乎存在名称冲突。正如您在将表重命名为
Person
时提到的,它按预期工作


根据我的经验,我总是在表中添加任意的表前缀,以避免这些类型的意外行为。

如果编写
时间表:~
,会发生什么情况?结果也是一样的。:/我已经在许多其他模型上以相同的方式定义了这些行为,并且它在这些模型上非常有效。我的用户模型一定有问题…嗯。。。奇怪的如果我将模型重命名为
Person
并重新生成,它工作得很好!?-也许我应该向条令团队提交一份bug报告。好吧,至少你找到了解决它的方法;)呵呵,是的:P-我在Doctrine bugtracker中创建了一张罚单,让他们知道这个问题。。。但是谢谢你的帮助!:)如果您编写
时间戳:~
,会发生什么情况?结果是一样的:我已经在许多其他模型上以相同的方式定义了这些行为,并且它在这些模型上非常有效。我的用户模型一定有问题…嗯。。。奇怪的如果我将模型重命名为
Person
并重新生成,它工作得很好!?-也许我应该向条令团队提交一份bug报告。好吧,至少你找到了解决它的方法;)呵呵,是的:P-我在Doctrine bugtracker中创建了一张罚单,让他们知道这个问题。。。但是谢谢你的帮助!:)