繁体   English   中英

使用doctrine 1.2创建查询,其中表名需要来自数据库

[英]Create Query with doctrine 1.2 in which table name needs to be from database

是否有可能使用doctrine(symfony 1.4)创建查询,其中我在from子句中从数据库(而不是schema.yml中的模型类)定义了表名?

例如:

在schema.yml我有模型类

StaticPage:
connection: doctrine
tableName: static_page
columns:
...

我的查询如下:

$item = Doctrine_Query::create();
$item->query("SELECT * FROM StaticPage WHERE id = ".$id);
$change = $item->fetchOne();
$change->setPublished(true);
$change->save();

在这个查询而不是StatigPage我需要static_page(tableName)...

谢谢...

Fracsi解决方案的其他方式:

$item = Doctrine::getTable("StaticPage")->findOneById($id);
    if($item instanceof StaticPage) {
        $item->setPublished(true);
        $item->save();
    }

始终使用您的型号/ ORM。 在很少情况下,Doctrine无法构建正确的查询语法,您必须自己编写sql。

广义版本:(通过参数传递模型名称(例如$sf_request

$item = Doctrine::getTable($model_name)->findOneById($id);
$item->setPublished(true);
$item->save();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM