我的问题是我似乎无法在多对多关系的情况下保湿Propel ORM对象,即使我使用find()从每个表中选择所有内容,它仍然会发送查询以防万一 - 很多关系。
我在stackoverflow和许多其他地方发现了很多关于此的问题,但没有一个对我有用。这是一个完全相同的问题,接受的答案对我来说也不起作用: find query for many to many relation propel
我的问题与其他架构完全相同。
我的schema.xml
<?xml version="1.0" encoding="utf-8"?>
<database name="propelDB" defaultIdMethod="native" defaultPhpNamingMethod="underscore" namespace="TestDB">
<table name="c_catalogs_locations" idMethod="native" phpName="CCatalogsLocations" isCrossRef="true">
<column name="catalogid" phpName="Catalogid" type="INTEGER" primaryKey="true" required="true"/>
<column name="locationid" phpName="Locationid" type="INTEGER" primaryKey="true" required="true"/>
<foreign-key foreignTable="catalogs">
<reference local="catalogid" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="locations">
<reference local="locationid" foreign="id"/>
</foreign-key>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
</table>
<table name="catalogs" idMethod="native" phpName="Catalogs">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="userid" phpName="Userid" type="INTEGER"/>
<column name="name" phpName="Name" type="VARCHAR" size="45" required="true"/>
<column name="images" phpName="Images" type="LONGVARCHAR"/>
<foreign-key foreignTable="users">
<reference local="userid" foreign="id"/>
</foreign-key>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
</table>
<table name="locations" idMethod="native" phpName="Locations">
<column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
<column name="location" phpName="Location" type="VARCHAR" size="45" required="true"/>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
</table>
</database>
我正在尝试的查询:
$locations = \Base\LocationsQuery::create()
->join("Locations.CCatalogsLocations")
->join("CCatalogsLocations.Catalogs")
->with("Catalogs")
->find();
foreach($locations as $location)
{
echo "- " . $location->getLocation() ."<br>";
foreach($location->getCatalogss() as $catalog) {
echo "-- " . $catalog . "<br>";
}
echo "<br>";
}
(我知道类名不是很好,但它只是一个测试项目,所以我不关心它。)
我正在使用和搜索的文档的链接:http://propelorm.org/documentation/ 我使用从git克隆的最新推进器和作曲家。
我一直在使用propel的文档但是我没有发现它已经写下来它无法做到这一点,但我也无法使用任何join(),joinWith()或with()方法解决它
我将propel设置为使用“classname”:“Propel \ Runtime \ Connection \ DebugPDO”,因此它会记录发出的每个查询,并且我尝试的任何查询都显示我的对象没有正确地保持水分并且每次都会触发查询我在多对多连接的一侧调用$ location-&gt; getCatalogss()。
推进日志:
[2014-10-17 09:25:50] propelDB.INFO: SELECT locations.id, locations.location, catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM locations INNER JOIN c_catalogs_locations ON (locations.id=c_catalogs_locations.locationid) INNER JOIN catalogs ON (c_catalogs_locations.catalogid=catalogs.id) [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=8 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=9 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=10 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=13 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=14 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=15 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=11 [] []
[2014-10-17 09:25:51] propelDB.INFO: SELECT catalogs.id, catalogs.userid, catalogs.name, catalogs.images FROM catalogs INNER JOIN c_catalogs_locations ON (catalogs.id=c_catalogs_locations.catalogid) WHERE c_catalogs_locations.locationid=12 [] []
我看到首先激发的SELECT查询是我想要使用的那个,因此它获取与其目录行相关的所有Location行,但它只会保存位置而不是目录。 即使使用2个查询来分别水合位置和目录甚至是crossRefTable并使用Propel处理连接也可以这样做,但即使我给它们加水,但推进仍然不使用它的本地数据但是发出单独的查询
我做错了吗?你是怎么解决的? 任何想法如何用自定义水合作用来解决它所以它需要尽可能多的查询,因为它们有很多表(它们不会是大数据表的大表,所以查询整个表不是问题,我还是需要它们)