0

我需要运行以下查询:

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]

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

只是为了提供更多信息,使用echo $c->toString();exit;打印 SQL 曾是

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
4

1 回答 1

2

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

于 2012-08-30T14:24:25.097 回答