Propel ORM-连接不相关的表 [英] Propel ORM - Joining unrelated tables

查看:111
本文介绍了Propel ORM-连接不相关的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此SQL语句如何转换为Propel(1.6.3)?

How does this SQL statement translate into Propel (1.6.3)?

SELECT * FROM table_a JOIN table_b

tableA和tableB不共享外键,也没有定义关系.

With tableA and tableB sharing no Foreign Keys and having no relationships defined.

TableAQuery::create()->join('tableB')

不起作用,因为Propel报错:

doesn't work since Propel complains with an error:

致命错误:消息为"TableA表上的未知关系TableB"的未捕获异常'PropelException'

"Fatal error: Uncaught exception 'PropelException' with message 'Unknown relation TableB on the TableA table'

非常感谢您的帮助和提示!这是我在这里的第一篇文章,希望我还没有做错任何事情:-)(在发布之前,我已经进行了彻底的搜索!)

Thanks very much in advance for any help and hints! This is my first post here and I hope I haven't done anything wrong yet :-) (I've searched thoroughly before I posted!)

推荐答案

您可以使用原始SQL语法解决此限制.例如:

You can work around this limitation by using raw SQL syntax. For instance:

$con = Propel::getConnection(SomePeer::DATABASE_NAME);
$query = 'SELECT * FROM `table_a` JOIN `table_b` LIMIT 10';
$stmt = $con->prepare($query);
if($stmt->execute()) {
    $res = $stmt->fetchAll();
    var_dump($res);
}

注释#1:这些联接可能会变得很大,并很快耗尽允许的内存大小.这就是为什么我添加了LIMIT.

Note #1: These kind of joins can become very big and quickly exhaust the allowed memory size. That's why I've added a LIMIT.

注2:输出不是很干净,既包含数字键又包含关联键.也许有办法可以改善这一点.

Note #2: The output isn't very clean, arrays of both numeric and associative keys. Maybe there are ways to improve this.

这篇关于Propel ORM-连接不相关的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆