You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jonathan Porterfield <a0...@hotmail.com> on 2001/09/19 23:43:40 UTC

Inheritance in Torque/Peers


I'm not sure I totally get this, so can someone please check my 
understanding of the usage from my example below?

Would this be the correct way to define inheritance between a base user 
table and an authors table in the database definition...

Where the two tables have the following definition.
------------       ------------
|   USERS    |---o-|   AUTHORS  |
-------------      ------------

<app-data>

<database name=MyData>

  <table name="USERS" idMethod="idbroker">
    <column name="USERID" inheritance="single" type="INTEGER" size="4" 
primaryKey="true"/>
        <inheritance key="AUTHORS" class="AUTHORS" 
extends="com.mycompany.project.om.USERS"/>
    <column name="USER_NAME" type="VARCHAR" size="255" />
  </table>

  <table name="AUTHORS" idMethod="idbroker" >
    <column name="AUTHORID" type="INTEGER" size="4" primaryKey="true" 
required="true"/>
    <column name="USERID" type="INTEGER" size="4" />
    <column name="AUTHOR_BIO" type="VARCHAR" size="255"/>
    <foreign-key foreighTable="USERS">
      <reference foreign=  local=>
    </foreign-key>
  </table>

</database>

</app-data>
------------------
Here, AUTHORS extends USERS so...
1) Criteria crit = new Criteria();
   AuthorsPeer.doSelect(crit);

   should fetch
   - USERID, USER_NAME, AUTHORID, AUTHOR_BIO

   (T/F)?

2) And by the same token, and although it would be unconventional, it would 
be possible to use
   Criteria crit = new Criteria();
   crit.add (AuthorsPeer.UserName,"Ralph Malph");
   Object o = CategoryPeer.doInsert (crit);

   to add a "Ralph Malph" user to the USERS table
   (T/F)?

3) Will this also create a row in the AUTHORS table?

4) Question - If inheritance is defined, is foreign-key definition redundant 
to the point of uselessness?

5) I see in the DTD that the attribute "extends" of the element 
"inheritance" is optional (#IMPLIED).
   What would be the effect of removing the extends attribute from the 
inheritance attribute in the example above?

Thanks in advance for any response
-Cheers

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


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


Re: Inheritance in Torque/Peers

Posted by John McNally <jm...@collab.net>.
Torque supports only the one table per class hierarchy style of o-r
mapping.  The <inheritance> tag is an element of <column> not <table>. 
It marks the column as distinguishing the different classes that are
stored within the table.  Leaving the extends attribute out will have
the class extend the highest level class, the extends attribute can lead
to a deeper hierarchy.

Jonathan Porterfield wrote:
> 
> I'm not sure I totally get this, so can someone please check my
> understanding of the usage from my example below?
> 
> Would this be the correct way to define inheritance between a base user
> table and an authors table in the database definition...
> 
> Where the two tables have the following definition.
> ------------       ------------
> |   USERS    |---o-|   AUTHORS  |
> -------------      ------------
> 
> <app-data>
> 
> <database name=MyData>
> 
>   <table name="USERS" idMethod="idbroker">
>     <column name="USERID" inheritance="single" type="INTEGER" size="4"
> primaryKey="true"/>
>         <inheritance key="AUTHORS" class="AUTHORS"
> extends="com.mycompany.project.om.USERS"/>
>     <column name="USER_NAME" type="VARCHAR" size="255" />
>   </table>
> 
>   <table name="AUTHORS" idMethod="idbroker" >
>     <column name="AUTHORID" type="INTEGER" size="4" primaryKey="true"
> required="true"/>
>     <column name="USERID" type="INTEGER" size="4" />
>     <column name="AUTHOR_BIO" type="VARCHAR" size="255"/>
>     <foreign-key foreighTable="USERS">
>       <reference foreign=  local=>
>     </foreign-key>
>   </table>
> 
> </database>
> 
> </app-data>
> ------------------
> Here, AUTHORS extends USERS so...
> 1) Criteria crit = new Criteria();
>    AuthorsPeer.doSelect(crit);
> 
>    should fetch
>    - USERID, USER_NAME, AUTHORID, AUTHOR_BIO
> 
>    (T/F)?
> 
> 2) And by the same token, and although it would be unconventional, it would
> be possible to use
>    Criteria crit = new Criteria();
>    crit.add (AuthorsPeer.UserName,"Ralph Malph");
>    Object o = CategoryPeer.doInsert (crit);
> 
>    to add a "Ralph Malph" user to the USERS table
>    (T/F)?
> 
> 3) Will this also create a row in the AUTHORS table?
> 
> 4) Question - If inheritance is defined, is foreign-key definition redundant
> to the point of uselessness?
> 
> 5) I see in the DTD that the attribute "extends" of the element
> "inheritance" is optional (#IMPLIED).
>    What would be the effect of removing the extends attribute from the
> inheritance attribute in the example above?
> 
> Thanks in advance for any response
> -Cheers
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

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