zend 框架从另一个表更新
我在 Zend Framework 中获得了扩展 Zend_Db_Table
的模型,其中 $this->_name = 'tableA'
。
我执行 insert()
、update()
或 delete()
的时间非常好。我如何实现根据另一个表的值更新主表..?
在原始 SQL 查询中,它可能如下所示:
UPDATE tableA SET fieldA = tableB.newValue
FROM tableB
WHERE tableA.someValue = tableB.someIndex // it will be complicate manipulation
AND tableA.index = .....
如何为 update()
方法构建参数:
parent::update( $data, $where );
I got model in Zend Framework what extends Zend_Db_Table
where $this->_name = 'tableA'
.
It is very nice how long I doing insert()
, update()
, or delete()
. How I can realize updating main table based on value from another table.. ?
In raw SQL query it could looks like this:
UPDATE tableA SET fieldA = tableB.newValue
FROM tableB
WHERE tableA.someValue = tableB.someIndex // it will be complicate manipulation
AND tableA.index = .....
how I can build params for update()
method:
parent::update( $data, $where );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有可能的组合来构建
parent::update()
方法的参数来获取最终的更新查询。原因是因为 Db Tableupdate
方法只是将您的$data
和$where
变量传递给 Db Adapter 的update方法。适配器的
update
方法没有留下附加附加信息的空间。 您根本无法破解参数如果您无法使用级联更新的表关系,那么 。最好的选择是扩展数据库适配器并创建一个新方法来处理这些类型的更新。这应该有效。
注意:我没有对此进行测试,但我非常有信心它会按预期工作。如果您有任何问题,请告诉我。因为我复制了适配器的更新方法,所以我继续添加了无法破解这些参数的原因的注释。
编辑
我差点忘了提。每个适配器都是唯一的,因此您必须检查您的适配器更新方法。我刚刚从
Zend_Db_Abstract
复制。There are no possible combinations of how to build params for the
parent::update()
method to get that final update query. The reason is because the Db Tableupdate
method just passes along your$data
and$where
variables to the Db Adapter'supdate
method. The adapter'supdate
method leaves no room for attaching additional information. You can't hack params at allIf you can't use table relationships with cascade update. Your best bet will be to extend the Db Adapter and create a new method to handle these types of updates. This should work.
Note: I didn't test this out, but I am pretty confident it will work as expected. If you have any problems, just let me know. Because I copied the adapter's update method, I went ahead and added notes of the reasons why you can't hack those params.
EDIT
I almost forgot to mention. Every adapter is unique so you will have to check with your adapters update method. I just copied from
Zend_Db_Abstract
.我认为你需要这个: http://framework.zend.com /manual/en/zend.db.table.relationships.html
I think you need this: http://framework.zend.com/manual/en/zend.db.table.relationships.html