Question

I'm trying get from my database some informations with this Query :

$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();

Here is the part of my schema.xml file with the concerned tables :

<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>

When i'm trying to execute this query I received this error message :

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

I know that I can use an alias for the 2nd use of the "top" table (useTopRelatedByIdTopEndQuery) but I can't find a way to do it.

I'm also having another problem, when I try with only one use just to verify that I'm correctly retrieving datas from my DB I don't have any BroadcastPart inside my Broadcast object.

Here is a dump of one of my Broadcast inside my collection :

[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
                    (
                    )

            )
Était-ce utile?

La solution

Alias for the query is actually represented by parameter to which you are passing null

Try the following code

$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();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top