在Symfony 1.4.11 / Propel 1.4.2中加入查询异常

时间:2012-08-30 14:12:21

标签: symfony-1.4 propel

我需要运行以下查询:

SELECT 
    m.TITLE, 
    m.MOMENTOIMAGE, 
    s.CREATED_AT, 
    s.UNREAD, 
    mem.FIRSTNAME, 
    mem.LASTNAME, 
    mem.MEMBER_PHOTO,
    mem.ID 
FROM `momento_send` s,
    `send_distribution` sd,
    `momento_distribution` d,
    `momento` m,
    `member` mem
WHERE
    s.momento_idmember=6 AND
    sd.id_send=s.id AND
    sd.id_distribution=d.id AND
    d.momento_id=m.id;

为此,我在Symfony 1.4中编写了以下代码(使用Propel 1.4.2)(感谢@ j0k)

$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(MomentoPeer::TITLE);
$c->addSelectColumn(MomentoPeer::MOMENTOIMAGE);
$c->addSelectColumn(MomentoSendPeer::CREATED_AT);
$c->addSelectColumn(MomentoSendPeer::UNREAD);
$c->addSelectColumn(MemberPeer::FIRSTNAME);
$c->addSelectColumn(MemberPeer::LASTNAME);
$c->addSelectColumn(MemberPeer::MEMBER_PHOTO);
$c->addSelectColumn(MemberPeer::ID);

$c->addJoin(SendDistributionPeer::ID_SEND, MomentoSendPeer::ID, Criteria::INNER_JOIN);
$c->addJoin(SendDistributionPeer::ID_DISTRIBUTION, MomentoDistributionPeer::ID, Criteria::INNER_JOIN);
$c->addJoin(MomentoDistributionPeer::MOMENTO_ID, MomentoPeer::ID, Criteria::INNER_JOIN);
$c->addJoin(MomentoDistributionPeer::MOMENTO_IDMEMBER, MemberPeer::ID, Criteria::INNER_JOIN);

$c->add(MomentoSendPeer::MOMENTO_IDMEMBER, $memberid);

//echo $c->toString();exit;

$records = SendDistributionPeer::doSelect($c);

运行此代码生成以下错误

[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 JOIN momento_send ON (send_distribution.ID_SEND=momento_send.ID) INNER JOI' at line 1]

有人可以建议,问题是什么。

只是提供更多信息,SQL打印 echo $ c-> toString();退出;

SELECT momento.TITLE, 
    momento.MOMENTOIMAGE, 
    momento_send.CREATED_AT, 
    momento_send.UNREAD, 
    member.FIRSTNAME, 
    member.LASTNAME, 
    member.MEMBER_PHOTO,
    member.ID 
FROM 
    INNER JOIN momento_send ON (send_distribution.ID_SEND=momento_send.ID) 
    INNER JOIN momento_distribution ON (send_distribution.ID_DISTRIBUTION=momento_distribution.ID) 
    INNER JOIN momento ON (momento_distribution.MOMENTO_ID=momento.ID) 
    INNER JOIN member ON (momento_distribution.MOMENTO_IDMEMBER=member.ID) 
WHERE momento_send.MOMENTO_IDMEMBER=6

1 个答案:

答案 0 :(得分:2)

尝试使用$c->setPrimaryTableName(MomentoPeer::TABLE_NAME);