Php 促进多对多水合问题
我的问题是,在多对多关系的情况下,我似乎无法创建ORM对象,即使我使用find()从每个表中选择所有内容,在多对多关系的情况下,它仍然会发送查询 我在stackoverflow和其他很多地方发现了很多关于这个的问题,但是没有一个适合我。这是一个完全相同的问题,有一个公认的答案,但对我来说也不适用: 我的问题与其他模式完全相同 myschema.xmlPhp 促进多对多水合问题,php,mysql,propel,Php,Mysql,Propel,我的问题是,在多对多关系的情况下,我似乎无法创建ORM对象,即使我使用find()从每个表中选择所有内容,在多对多关系的情况下,它仍然会发送查询 我在stackoverflow和其他很多地方发现了很多关于这个的问题,但是没有一个适合我。这是一个完全相同的问题,有一个公认的答案,但对我来说也不适用: 我的问题与其他模式完全相同 myschema.xml <?xml version="1.0" encoding="utf-8"?> <database name="propelDB
<?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>
我看到,首先触发的SELECT查询是我想要使用的查询,因此它会获取与其目录行连接的所有位置行,但它只获取位置,而不是目录。
即使使用2个查询来分别添加位置和目录,甚至crossRefTable,并让Propel处理联接,也可以这样做,但即使我添加了它们,但Propel仍然不使用其本地数据,而是发送单独的查询
我做错什么了吗?你是怎么解决的?
有没有想过如何通过自定义查询来解决这个问题,这样就需要尽可能多的查询表(它们不会是包含大数据的大型表,所以查询整个表不是问题,反正我需要它们)
$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>";
}
[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 [] []