You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Zé Carlos <ze...@gmail.com> on 2008/11/19 15:00:31 UTC

Foreign Key

Hello, probably i have a silly question, I was testing torque and i have a
schema with a onte-to-one relation mapped like this:

    <table name="novos_jogadores" javaName="NovoJogador">
        <column name="id" javaName="id" primaryKey="true" required="true"
type="INTEGER" />
        <foreign-key foreignTable="jogadores" name="id">
            <reference local="id" foreign="novo_jogador_id" />
        </foreign-key>
    </table>

    <table name="jogadores" javaName="Jogador">
        <column name="id" javaName="id" primaryKey="true" required="true"
type="INTEGER" />
        <column name="novo_jogador_id" javaName="novoJogadorId"
type="INTEGER" />
        <foreign-key foreignTable="novos_jogadores" name="novo_jogador_id">
            <reference local="novo_jogador_id" foreign="id" />
        </foreign-key>
    </table>

on the table 'novos_jogadores' i mapped 'id' as foreign key referencing a
foreign key on 'jogadores', this forces the generator to build a
NovoJogadorPeer.getJogador(NovoJogador x), is any problem with this kind of
mapping with updates, deletions and insertions?

regards

Re: Foreign Key

Posted by Philip Reimann <re...@synyx.de>.

Thomas Fischer schrieb:
>>     <table name="novos_jogadores" javaName="NovoJogador">
>>         <column name="id" javaName="id" primaryKey="true" 
> required="true"
>> type="INTEGER" />
>>         <foreign-key foreignTable="jogadores" name="id">
>>             <reference local="id" foreign="novo_jogador_id" />
>>         </foreign-key>
>>     </table>
>>
>>     <table name="jogadores" javaName="Jogador">
>>         <column name="id" javaName="id" primaryKey="true" 
> required="true"
>> type="INTEGER" />
>>         <column name="novo_jogador_id" javaName="novoJogadorId"
>> type="INTEGER" />
>>         <foreign-key foreignTable="novos_jogadores" 
> name="novo_jogador_id">
>>             <reference local="novo_jogador_id" foreign="id" />
>>         </foreign-key>
>>     </table>
>>
>> on the table 'novos_jogadores' i mapped 'id' as foreign key referencing 
> a
>> foreign key on 'jogadores', this forces the generator to build a
>> NovoJogadorPeer.getJogador(NovoJogador x), is any problem with this kind 
> of
>> mapping with updates, deletions and insertions?
> 
> Looks strange to me. I usually model a 1:1 relation like a 1:n relation 
> (of which the 1:1 relation is a special case)
> Torqe treats this as a circular relationship rather than a 1:1 
> relationship so things can happen that you'd not expect.
> 
> But if it works for you, nobody prevents you from modeling the 
> relationship like you did.
> 
>   Thomas

As far as I know there is a problem when using the Torque ID Broker
(ID_TABLE). Due to the fact, that there a entries for every table, there
might be problems if the nex ID for table novos_jogadores differs from
the next ID for table jogadores. This happens if you insert in one
table, but not in the other.
You use FKs in both tables, so this might not happen in your schema.

greetings Philip

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


RE: Foreign Key

Posted by Thomas Fischer <fi...@seitenbau.net>.
>     <table name="novos_jogadores" javaName="NovoJogador">
>         <column name="id" javaName="id" primaryKey="true" 
required="true"
> type="INTEGER" />
>         <foreign-key foreignTable="jogadores" name="id">
>             <reference local="id" foreign="novo_jogador_id" />
>         </foreign-key>
>     </table>
> 
>     <table name="jogadores" javaName="Jogador">
>         <column name="id" javaName="id" primaryKey="true" 
required="true"
> type="INTEGER" />
>         <column name="novo_jogador_id" javaName="novoJogadorId"
> type="INTEGER" />
>         <foreign-key foreignTable="novos_jogadores" 
name="novo_jogador_id">
>             <reference local="novo_jogador_id" foreign="id" />
>         </foreign-key>
>     </table>
> 
> on the table 'novos_jogadores' i mapped 'id' as foreign key referencing 
a
> foreign key on 'jogadores', this forces the generator to build a
> NovoJogadorPeer.getJogador(NovoJogador x), is any problem with this kind 
of
> mapping with updates, deletions and insertions?

Looks strange to me. I usually model a 1:1 relation like a 1:n relation 
(of which the 1:1 relation is a special case)
Torqe treats this as a circular relationship rather than a 1:1 
relationship so things can happen that you'd not expect.

But if it works for you, nobody prevents you from modeling the 
relationship like you did.

  Thomas