QCubed - 在多列上连接表
QCubed - Join tables on multiple columns
我们公司继承了一个使用Qcubed PHP框架的应用。该框架的特点之一是 QQuery 查询方法。我们无法确定是否可以使用 QQuery 在两列的两个表之间创建连接。
还有 QCubed 开发人员吗?
还有 QCubed 开发人员吗? -> 是的,很多。大多数动作都可以在 github
上找到
https://github.com/qcubed/qcubed
加入:
QQuery 的有趣之处在于,当在表之间设置了正确的外键时,它会自动连接表。示例页面有大量相关信息,请查看:
http://qcu.be/examples/index.php
额外提示:请务必在加载之前定义您的连接。 Qcubed 会在请求相关对象时自动进行连接,但最好提前展开它们。
快速示例:
//loads a Person object into memory
//select * from person where id = 1;
$objPerson = Person::Load(1);
echo $objPerson->Name . ' lives in ' . $objPerson->Town->Name;//will cause a query in the style "select * from town where id=x;"
//loads a Person object into memory, and joins the Town table.
//select * from person LEFT JOIN town on town.id = person.town_id where id = 1;
$objPerson = Person::Load(1, QQ::Clause(QQ::Expand(QQN::Person()->Town)));
echo $objPerson->Name . ' lives in ' . $objPerson->Town->Name;//no extra query, town was already joined by the expand.
两者都会return相同的数据,但后者效率更高。
回答有关将 2 列作为主要列的部分:我不是 100% 确定,我从未以这种方式使用过 QCubed。但是,查看 http://qcu.be/examples/vendor/qcubed/framework/assets/php/examples/code_generator/primary_keys.php 其中提到:
QCubed also offers some support for tables that have multiple-column Primary Keys defined on it. For tables that have multi-column Primary Keys, QCubed will fully generate the object itself. But note that you will not be able to use this generated object as a related object for another table (in other words, QCubed does not support multi-column Foreign Keys). However, with all the generated Load methods in these objects, it is still possible to fully develop an application with tables that use multi-column Foreign Keys. Basically, whenever you want to access a related object via a multi-column Foreign Key, you can simply call that object's Load method directly to retrieve that object.
如果您想定义没有外键的关系,请查看本地安装中的 codegen.xml 文件。
我们公司继承了一个使用Qcubed PHP框架的应用。该框架的特点之一是 QQuery 查询方法。我们无法确定是否可以使用 QQuery 在两列的两个表之间创建连接。
还有 QCubed 开发人员吗?
还有 QCubed 开发人员吗? -> 是的,很多。大多数动作都可以在 github
上找到https://github.com/qcubed/qcubed
加入: QQuery 的有趣之处在于,当在表之间设置了正确的外键时,它会自动连接表。示例页面有大量相关信息,请查看:
http://qcu.be/examples/index.php
额外提示:请务必在加载之前定义您的连接。 Qcubed 会在请求相关对象时自动进行连接,但最好提前展开它们。
快速示例:
//loads a Person object into memory
//select * from person where id = 1;
$objPerson = Person::Load(1);
echo $objPerson->Name . ' lives in ' . $objPerson->Town->Name;//will cause a query in the style "select * from town where id=x;"
//loads a Person object into memory, and joins the Town table.
//select * from person LEFT JOIN town on town.id = person.town_id where id = 1;
$objPerson = Person::Load(1, QQ::Clause(QQ::Expand(QQN::Person()->Town)));
echo $objPerson->Name . ' lives in ' . $objPerson->Town->Name;//no extra query, town was already joined by the expand.
两者都会return相同的数据,但后者效率更高。
回答有关将 2 列作为主要列的部分:我不是 100% 确定,我从未以这种方式使用过 QCubed。但是,查看 http://qcu.be/examples/vendor/qcubed/framework/assets/php/examples/code_generator/primary_keys.php 其中提到:
QCubed also offers some support for tables that have multiple-column Primary Keys defined on it. For tables that have multi-column Primary Keys, QCubed will fully generate the object itself. But note that you will not be able to use this generated object as a related object for another table (in other words, QCubed does not support multi-column Foreign Keys). However, with all the generated Load methods in these objects, it is still possible to fully develop an application with tables that use multi-column Foreign Keys. Basically, whenever you want to access a related object via a multi-column Foreign Key, you can simply call that object's Load method directly to retrieve that object.
如果您想定义没有外键的关系,请查看本地安装中的 codegen.xml 文件。