1

我正在尝试使用此查询从我的数据库中获取一些信息:

$broadcastsQuery = BroadcastQuery::create()
        ->limit(20);
        ->useBroadcastPartQuery(null, \Criteria::INNER_JOIN)
            ->useTopRelatedByIdTopBeginQuery(null, \Criteria::INNER_JOIN)
            ->endUse()
            ->useTopRelatedByIdTopEndQuery(null, \Criteria::RIGHT_JOIN)
            ->endUse()
        ->endUse()
        ->filterBySended(true)
        ->find();

这是我的 schema.xml 文件中包含相关表的部分:

<table name="broadcast">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="id_channel" type="integer" />
    <column name="id_media" type="integer" />
    <column name="start_at" type="timestamp" />
    <column name="title" type="varchar" size="255" />
    <column name="sended" type="boolean" />
    <unique name="broadcast_id_plurimedia">
        <unique-column name="id_plurimedia" />
    </unique>
    <foreign-key foreignTable="channel">
        <reference local="id_channel" foreign="id" />
    </foreign-key>
</table>
<table name="broadcast_part">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="id_broadcast" type="integer" />
    <column name="id_top_begin" type="integer" />
    <column name="id_top_end" type="integer" />
    <foreign-key foreignTable="broadcast">
        <reference local="id_broadcast" foreign="id" />
    </foreign-key>
    <foreign-key foreignTable="top">
        <reference local="id_top_begin" foreign="id" />
    </foreign-key>
    <foreign-key foreignTable="top">
        <reference local="id_top_end" foreign="id" />
    </foreign-key>
</table>
<table name="top">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="id_channel" type="integer" />
    <column name="genre" type="varchar" size="20" />
    <column name="source" type="varchar" size="20" />
    <column name="real_date" type="timestamp" />
    <column name="frame" type="tinyint" />
    <column name="title" type="varchar" size="255" />
    <column name="orphan" type="boolean" />
    <column name="type" type="varchar" size="10" />
    <foreign-key foreignTable="channel">
        <reference local="id_channel" foreign="id" />
    </foreign-key>
</table>

当我尝试执行此查询时,我收到此错误消息:

...Syntax error or access violation: 1066 Not unique table/alias: "top"...

我知道我可以使用别名来第二次使用“顶部”表 (useTopRelatedByIdTopEndQuery),但我找不到办法。

我还遇到了另一个问题,当我尝试仅使用一次来验证我是否从我的数据库中正确检索数据时,我的 Broadcast 对象中没有任何 BroadcastPart。

这是我收藏中的一个广播的转储:

[0] => Broadcast Object
            (
                [startCopy:protected] => 
                [id:protected] => 1
                [id_channel:protected] => 328
                [start_at:protected] => 2013-09-05 09:31:00
                [title:protected] => Killo Design
                [sended:protected] => 1
                [aChannel:protected] => 
                [collBroadcastParts:protected] => 
                [collBroadcastPartsPartial:protected] => 
                [alreadyInSave:protected] => 
                [alreadyInValidation:protected] => 
                [alreadyInClearAllReferencesDeep:protected] => 
                [broadcastPartsScheduledForDeletion:protected] => 
                [validationFailures:protected] => Array
                    (
                    )

                [_new:protected] => 
                [_deleted:protected] => 
                [modifiedColumns:protected] => Array
                    (
                    )

                [virtualColumns:protected] => Array
                    (
                    )

            )
4

1 回答 1

1

查询的别名实际上由您传递的参数表示null

试试下面的代码

$broadcastsQuery = BroadcastQuery::create('a')
    ->limit(20);
    ->useBroadcastPartQuery('b', \Criteria::INNER_JOIN)
        ->useTopRelatedByIdTopBeginQuery(null, \Criteria::INNER_JOIN)
        ->endUse()
        ->useTopRelatedByIdTopEndQuery('c', \Criteria::RIGHT_JOIN)
        ->endUse()
    ->endUse()
    ->filterBySended(true)
    ->find();
于 2013-09-06T06:50:53.127 回答