Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

One to Many multiple relationship #751

Open
francescodoffizi opened this Issue · 2 comments

2 participants

@francescodoffizi

In a model like:

<table name="partite" phpName="Partite" idMethod="native">
    <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
    <column name="squadra_in_casa" phpName="SquadraInCasa" type="INTEGER" required="true"/>
    <column name="squadra_fuori_casa" phpName="SquadraFuoriCasa" type="INTEGER" required="true"/>
    <column name="giornate_id" phpName="GiornateId" type="INTEGER" required="true"/>
    <column name="goal_squadra_in_casa" phpName="GoalSquadraInCasa" type="INTEGER" required="false"/>
    <column name="goal_squadra_fuori_casa" phpName="GoalSquadraFuoriCasa" type="INTEGER" required="false"/>
    <column name="nota" phpName="Nota" type="VARCHAR" size="45" required="false"/>
    <foreign-key foreignTable="giornate" name="fk_partite_giornate1">
        <reference local="giornate_id" foreign="id"/>
    </foreign-key>
    <foreign-key foreignTable="squadre" name="fk_partite_squadre1">
        <reference local="squadra_in_casa" foreign="id"/>
    </foreign-key>
    <foreign-key foreignTable="squadre" name="fk_partite_squadre2">
        <reference local="squadra_fuori_casa" foreign="id"/>
    </foreign-key>
    <index name="fk_partite_squadre1_idx">
        <index-column name="squadra_in_casa"/>
    </index>
    <index name="fk_partite_squadre2_idx">
        <index-column name="squadra_fuori_casa"/>
    </index>
    <index name="fk_partite_giornate1_idx">
        <index-column name="giornate_id"/>
    </index>
    <vendor type="mysql">
        <parameter name="Engine" value="InnoDB"/>
    </vendor>
</table>

It seems Propel is not able to perform joins on fk_partite_squadre1 and fk_partite_squadre2, a query like

PartiteQuery::create() ->joinWith('Partite.SquadraInCasa')->joinWith('Partite.SquadraFuoriCasa') ->join('Giornate') -> orderByGiornateId('asc') ->paginate($page, $perpage)

returns
Unknown table or alias Partite
exception.

Even using Join doesn't seem woorking, it seems something like http://trac.propelorm.org/ticket/876 old issue.

@jaugustin
Collaborator

@francescodoffizi I think you don't need to write this :

PartiteQuery::create() ->joinWith('SquadraInCasa')->joinWith('SquadraFuoriCasa') ->join('Giornate') -> orderByGiornateId('asc') ->paginate($page, $perpage)
@francescodoffizi

Any other way to get both linked Squadre objects fails with an error, some ideas not having to issue manual queries to DB?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.