代码之家  ›  专栏  ›  技术社区  ›  DerKlops

PHPs原则创造了空记录

  •  1
  • DerKlops  · 技术社区  · 14 年前

    我玩了很多第1.2条。创建和删除记录不再是问题;)。但有时我的数据库中有空记录。每个字段都设置为空。我觉得这和关系有关。我怎么能阻止创建这种空条目的原则。

    3 回复  |  直到 14 年前
        1
  •  1
  •   jamil    14 年前

    在架构中,使用标记notnull:true强制非空字段 使用primary:true表示id 即。:

    table:
      columns:
        id:
          primary: true
          unsigned: true
          type: integer(4)
          autoincrement: true
        field:
          type: ...
          notnull: true
    

        2
  •  0
  •   FloydThreepwood    14 年前

    这在法典中应该是个问题,条令本身并不会产生空的记录。我相信你在某个地方保存了一个空填充模型。

    小心 notnull:true

        3
  •  0
  •   cmc Brian Carper    12 年前

    到目前为止,我只发现这个有点老套的解决方案,可以为每个相关字段插入一个空值。

    public function preSave($trigger) {
    
      // Avoid empty relations
      if(!$this->getRelatedobjectId())
        $this->setRelatedobject(null);
      }
    }