0

我将如何忽略 Zend_DB save() 尝试填写创建的列?对于某个模型,我不需要该列。

4

2 回答 2

1

不要发送数据。save()Zend_Db_Table_Rowapi 的一部分,被设计成在将数据保存到一行的方式上有点智能。它将根据需要执行插入或更新行。

save()也只会更新它有数据的列。如果您不为创建的列发送新数据,save()则不会覆盖数据。

只要有可能,我就让我正在使用的数据库创建和更新创建和更新的列。这样我就可以在需要时查询信息,但我不必使用 PHP 做一些我的数据库可以做得更好的事情。

于 2013-02-07T06:44:13.267 回答
0

Check out http://framework.zend.com/manual/1.12/en/zend.db.table.html Section "Advanced usage".

For more specific and optimized requests, you may wish to limit the number of columns returned in a row or rowset. This can be achieved by passing a FROM clause to the select object. The first argument in the FROM clause is identical to that of a Zend_Db_Select object with the addition of being able to pass an instance of Zend_Db_Table_Abstract and have it automatically determine the table name.

Important

The rowset contains rows that are still 'valid' - they simply contain a subset of the columns of a table. If a save() method is called on a partial row then only the fields available will be modified.

So, if you called an update() I think it would be as simple as unsetting the value for the column you don't want to touch. Of course database constraints will need to be honored - i.e. column should allow nulls.

于 2013-02-06T20:53:37.197 回答