[EMAIL PROTECTED] wrote:
> 
> Hi,
> 
> I've been working with Turbine for a couple of weeks, on and off, and
> am finally getting to the point where I would need to do some joins
> between some tables to build some output for the users.
> 
> I'm using Torque to generate the om classes, and for example, my db
> looks something like this:
> 
> TABLE A
>    A_ID INTEGER
>    B_ID INTEGER
>    SCORE INTEGER
> 
> TABLE B
>    B_ID INTEGER
>    C_ID INTEGER
>    NAME VARCHAR
> 
> TABLE C
>    C_ID INTEGER
>    NAME VARCHAR
> 
> The foriegn keys are declared and matched up in my torque definition.
> 
> So each of these tables is represented by a peer object, and I'm trying
> to do something like
> 
> SELECT A.SCORE, B.NAME, C.NAME FROM A, B, C WHERE A.B_ID = B.B_ID AND
>   B.C_ID = C.C_ID;
> 

The Peer system is currently only set up to return all columns in a
table.  This might be slightly inefficient, but is more maintainable,
and I am not sure it is slower than some of the alternatives that would
make it easier to pick and choose.  But it would be nice to develop a
standard way to pick a subset, so please help.


> My question is, what is the preferred method to fit this into the peer
> model?  Do I create some new peer objects that have these columns
> defined?  When I do a select now, using one of the existing peer
> objects, say A's, I end up with a DataSetException.  My criteria creation
> is like this:
> 
> Criteria ct = new Criteria();
> ct.addSelectColumn(APeer.SCORE);
> ct.addSelectColumn(BPeer.NAME);
> ct.addSelectColumn(CPeer.NAME);
> ct.addJoin(APeer.B_ID, BPeer.B_ID);
> ct.addJoin(BPeer.C_ID, CPeer.C_ID);
> ct.addOrderByColumn(APeer.SCORE);
> 
> My understanding from the docs (which I have read, but can't find
> an example of a join) is that what will return from an
> 
> APeer.doSelect(ct);

addSelectColumn is used by APeer to add Columns in Table A.  row2Object
then expects the columns to be returned as APeer.addSelectColumns added
them.

> 
> will be a vector of rows for the results, cast as the data object,
> which knows nothing of these other tables (I assume the
> DataSetException is from when it's trying to cast one of the
> NAME strings into the INTEGER SCORE column in A).
> 
> Should I create a class that has the correct columns, and then call
> APeer.doSelect(), specifying this new class as the class to cast to
> (thought I notice in the source that this will use row2Object, which
> assumes that the peer's real data object is being used).  Or do I
> need to create a new peer altogether?  Or is there a cleaner solution
> I'm totally missing?
> 

If you choose the objectModel=complex in your torque.props, many join
methods will be created.  Maybe one will meet your needs, or at least
you will see how Peers can be used in joins, and you can add your own.

> Sorry for this being so long-winded...any pointers (even RTFM)
> or suggestions appreciated.

There is an advanced peer page that might be some help.  It links off
the main turbine docs.  Much of what is talked about is handled by
picking objectModel=complex, but the doc is better explaining the
details.

John McNally


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to