propelorm / sfPropelORMPlugin

symfony 1.x plugin for Propel.
http://www.propelorm.org/
Other
109 stars 95 forks source link

FROM INNER JOIN bug #235

Open Arkemlar opened 8 years ago

Arkemlar commented 8 years ago

In some cases new Propel version is generating wrong queries with omitted table name in FROM statement. Someone in stackoverflow said that in new propel version the right way to build queries is to use Queries, but as in main page mentioned, sfPropelORMPlugin fully supports BC. So I assume this as bug. Example:

$c = new Criteria();
$c->setDistinct();

$c->addJoin(ShopProduct2shopRubricPeer::PRODUCT_ID, ShopProductPeer::ID);
$c->addJoin(ShopProduct2shopRubricPeer::RUBRIC_ID, ShopRubricPeer::ID);
$c3 = $c->getNewCriterion(ShopRubricPeer::ID, array(99), Criteria::IN);
$c4 = $c->getNewCriterion(ShopRubricPeer::PARENT_ID, array(99), Criteria::IN);
$c4->addOr($c3);
$c->addAnd($c4);

$c->add(ShopProductPeer::VISIBLE, 1);
$c->add(ShopProductPeer::WAREHOUSE, 0, Criteria::GREATER_THAN);
$c->addDescendingOrderByColumn('RAND()');
$c->setLimit($limit);
$items =  ShopProductPeer::doSelect($c);

Error text: Unable to execute SELECT statement [SELECT DISTINCT shop_product.ID, shop_product.PARENT_ID, shop_product.RUBRIC_ID, <I excluded excess text>, shop_product.VISIBLE, FROM INNER JOINshop_productON (shop_product2shop_rubric.PRODUCT_ID=shop_product.ID) INNER JOINshop_rubricON (shop_product2shop_rubric.RUBRIC_ID=shop_rubric.ID) WHERE (shop_rubric.PARENT_ID IN (:p1) OR shop_rubric.ID IN (:p2)) AND shop_product.VISIBLE=:p3 AND shop_product.WAREHOUSE>:p4 ORDER BY RAND() DESC LIMIT 6] [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOINshop_productON (shop_product2shop_rubric.PRODUCT_ID=shop_product.I' at line 1]

rozwell commented 8 years ago

That's a Propel, not the sfPropelORMPlugin bug. But Propel should be BC too.

You excluded the excess text, so let me ask you about this part: shop_product.VISIBLE, FROM INNER JOIN Is the comma really between VISIBLE and FROM in generated query?

What's the schema for those tables, especially ShopProduct, to reproduce the issue?