cvs: pear /DB_DataObject TODO

From: Date: Wed, 04 Dec 2002 05:11:07 +0000
Subject: cvs: pear /DB_DataObject TODO
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7736@lists.php.net to get a copy of this message
alan_k Wed Dec 4 00:11:07 2002 EDT Modified files: /pear/DB_DataObject TODO Log: added notes on join concepts Index: pear/DB_DataObject/TODO diff -u pear/DB_DataObject/TODO:1.7 pear/DB_DataObject/TODO:1.8 --- pear/DB_DataObject/TODO:1.7 Mon Sep 16 23:49:19 2002 +++ pear/DB_DataObject/TODO Wed Dec 4 00:11:06 2002 @@ -47,3 +47,108 @@ $object->whereAdd("colour like 'r%'); $object->delete(TRUE); works OK - just uses the where condition, not the values. + + + + +---------------------------------- +Issue: Crosstable Joins + +Althought the main documents indicate that a join version ended up being too complex, this +was based on doing multiple joins on many tables. - It has been suggested (and code provided), +that doing a simpler version may be possible: + +One suggestion by Stejn de Reede was to do this + +$product = new DataObjects_Product(); +$product->get(24); +$img = new DataObjects_Image(); +$img->orderBy('product_image.sort'); +$product->getCrossLink($img); + +which would result in the queries: +SELECT * FROM produce WHERE id = 24; + +SELECT * from image + INNER JOIN product_image + ON product_image.image = image.id + WHERE product_image.product_id = 24 + ORDER BY product_image.sort; + + + +** Reservations: +* introduction of 'magic table' product_image, that is not clear from the code. +* use of assumed defaults like id and column names product_id which are 'magicly generated' - + The initial links code used this, and proved slightly troublesome - the links.ini file solved alot of this. +* query results have little relation to the object that they are exectuted on. (eg. product object is filled with image and product_image join results) + + +From a totally abstract view (thinking out loud), It would be clearer to do something like: + +$image = new DataObjects_Image; +$productimage = new DataObjects_Productimage +$productimage->productid = 24; + +$image->addJoin( $productimage ); +$image->orderBy('productimage.sort') +$image->findJoin(); + + +Which would build: + +SELECT * from image + + INNER JOIN productimage + ON productimage.image = image.id + + WHERE productimage.productid = 24 + ORDER BY productimage.sort; + + + +$productimage = new DataObjects_Productimage; +$product = new DataObjects_Product; +$image = new DataObjects_Image + +$product->id = 24; + +$productimage->addJoin( $image ); +$productimage->addJoin( $product ); + +$productimage->orderBy('productimage.sort') +$productimage->findJoin(); + + + +Which would build: + +SELECT * from productimage + INNER JOIN image + ON productimage.image = image.id + + INNER JOIN product + ON productimage.product = product.id + + WHERE product.id = 24 + ORDER BY productimage.sort; + + +** I've no idea is this query would work or is valuable - so it needs a bit of testing. + + + + +Based on a configuration: (joins.ini) // or could be shared with links.ini ? +[productimage] +;; many to 1 +;; joins table productimage:image to image:id +image = image:id +;; joins table productimage:product to product:id +product = product:id + + + + + +

« previous php.pear.cvs (#7736) next »