开发者

PHPs Doctrine creates empty records

I played a lot with Doctrine 1.2. Creating and deleting records are no problem anymore ;). But sometimes i have empty records 开发者_Go百科in my database. Every field is set to NULL. I have the feeling it has something to do with relations. How can i prevent Doctrine of creating such empty entries.


In your schema use the tag notnull: true to force non-empty fields and use primary: true for id's i.e.:

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

I this does not help you, please put further information


This should be a Problem in Code, Doctrine itself does not create empty records. I believe you save somewhere a null filled model.

Be carefull with notnull:true as it leads to incompatibilities with Oracle, if you don't solve above Problem.


I have only found this somewhat hackish solution so far, to be inserted for each related field for which a null values should be possible.

public function preSave($trigger) {

  // Avoid empty relations
  if(!$this->getRelatedobjectId())
    $this->setRelatedobject(null);
  }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜