I think that this could be made into a pattern which could be generated by
Torque.  I have one small problem with the code below though...it will
create multiple Vendor instances which contain the same data.  For example
if Model 1 and Model 2 both have Vendor 1, two Vendor Objects will be
created that are both vendor 1.

I would recommend adding the Vendors to a Hashtable, and then searching with
table.get(model.getVendorId()), and only if that returns null, doing
VendorPeer.rowToObject.

The main difficulty I can see for generalizing this is if the Class contains
many related classes.  Maybe each generated class which is the many side of
a 1 to many relationship should have a doSelectRelated which puts in all the
joins for getting the related classes. And the class which is the 1 side of
the 1 to many relationship would have a method void loadXXX which would load
the Vector of related objects. Then there could be a tag in the XML which
would specify whether the loadXXX methods should be called when the objects
are created.

What do you think of that?

        -Nissim

> 
> For this app I have models that each have a specific vendor. 
> In other words
> a one-to-many relation between vendor and model.  If I want 
> to select models
> with their associated Vendors I do it like this (I use some 
> code that is
> generated by newtorque and not the current torque version):
> 
>     public static Vector doSelectWithVendor ( Criteria 
> criteria ) throws
> Exception
>     {
>         // First add the model rows to select
>         addSelectColumns (criteria);
>         // Now we add all to Vendor rows as well
>         VendorPeer.addSelectColumns (criteria);
> 
>         // Force a join
>         criteria.addJoin (VENDOR_ID, VendorPeer.VENDOR_ID);
> 
>         // BasePeer returns a Vector of Value (Village) 
> arrays.  The array
>         // order follows the order columns were placed in the 
> Select clause.
>         Vector rows = BasePeer.doSelect(criteria);
>         Vector results = new Vector();
> 
>         // populate the object(s)
>         for ( int i=0; i<rows.size(); i++ )
>         {
>             Record row = (Record)rows.elementAt(i);
>             // Get the model from the first half of the row
>             Model model = row2Object (row,1);
>             // Get the vendor from the second half of the row
>             Vendor vendor = VendorPeer.row2Object (row,12);
>             // Add the vendor to the model
>             model.setVendor (vendor);
>             results.addElement (model);
>         }
> 
>         return results;
>     }
> 
> > Is it supported by Torque until now ?
> 
> We're thinking of features to add to torque, but I think it 
> will probably be
> a while before this is fully supported.
> 
> ~ Leon
> 
> 
> 
> ------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
> Problems?:           [EMAIL PROTECTED]
> 


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