代码之家  ›  专栏  ›  技术社区  ›  Dave Vogt

保存后使条令加载自动增加值

  •  3
  • Dave Vogt  · 技术社区  · 16 年前

    我使用的是数据库抽象原则。现在我想得到 auto_increment 新创建的主键(和 save() 'd)对象-但 $obj->toArray() 显示调用后字段为空 保存() .

    有我不知道的旗子吗?或者我真的需要从数据库中查询对象吗?

    2 回复  |  直到 16 年前
        1
  •  3
  •   Wickethewok    16 年前

    确保在中设置对象时设置了autoincrement标志。 setTableDefinition() 方法(或相关的yaml配置文件)。如果没有设置这个标志,那么条令就不知道要更新它。你应该有这样的东西:

     $this->hasColumn('id', 'integer', 4, array(
                      'type' => 'integer',
                      'length' => 4,
                      'fixed' => false,
                      'unsigned' => true,
                      'primary' => true,
                      'autoincrement' => true //this flag right here
                 )
     );
    
        2
  •  0
  •   prodigitalson    16 年前

    呼叫 refresh 在记录实例上 toArray .

    推荐文章