Adodb Dokumentation  V5.14 8 Sept 2011
tests/test-active-relationsx.php
00001 <?php
00002 global $err_count;
00003 $err_count = 0;
00004 
00005         function found($obj, $cond)
00006         {
00007                 $res = var_export($obj, true);
00008                 return (strpos($res, $cond));           
00009         }
00010         
00011         function notfound($obj, $cond)
00012         {
00013                 return !found($obj, $cond);
00014         }
00015         
00016         function ar_assert($bool)
00017         {
00018                 global $err_count;
00019                 if(!$bool)
00020                         $err_count ++;
00021                 return $bool;
00022         }
00023         
00024                 define('WEB', true);
00025         function ar_echo($txt)
00026         {
00027                 if(WEB)
00028                         $txt = str_replace("\n", "<br />\n", $txt);
00029                 echo $txt;
00030         }
00031 
00032         include_once('../adodb.inc.php');
00033         include_once('../adodb-active-recordx.inc.php');
00034         
00035 
00036         $db = NewADOConnection('mysql://root@localhost/test');
00037         $db->debug=0;
00038         ADOdb_Active_Record::SetDatabaseAdapter($db);
00039 
00040         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00041         ar_echo("Preparing database using SQL queries (creating 'people', 'children')\n");
00042 
00043         $db->Execute("DROP TABLE `people`");
00044         $db->Execute("DROP TABLE `children`");
00045         $db->Execute("DROP TABLE `artists`");
00046         $db->Execute("DROP TABLE `songs`");
00047 
00048         $db->Execute("CREATE TABLE `people` (
00049                         `id` int(10) unsigned NOT NULL auto_increment,
00050                         `name_first` varchar(100) NOT NULL default '',
00051                         `name_last` varchar(100) NOT NULL default '',
00052                         `favorite_color` varchar(100) NOT NULL default '',
00053                         PRIMARY KEY  (`id`)
00054                     ) ENGINE=MyISAM;
00055                    ");
00056         $db->Execute("CREATE TABLE `children` (
00057                                         `person_id` int(10) unsigned NOT NULL,
00058                         `name_first` varchar(100) NOT NULL default '',
00059                         `name_last` varchar(100) NOT NULL default '',
00060                         `favorite_pet` varchar(100) NOT NULL default '',
00061                         `id` int(10) unsigned NOT NULL auto_increment,
00062                         PRIMARY KEY  (`id`)
00063                     ) ENGINE=MyISAM;
00064                    ");
00065         
00066         $db->Execute("CREATE TABLE `artists` (
00067                         `name` varchar(100) NOT NULL default '',
00068                         `artistuniqueid` int(10) unsigned NOT NULL auto_increment,
00069                         PRIMARY KEY  (`artistuniqueid`)
00070                     ) ENGINE=MyISAM;
00071                    ");
00072 
00073         $db->Execute("CREATE TABLE `songs` (
00074                         `name` varchar(100) NOT NULL default '',
00075                         `artistid` int(10) NOT NULL,
00076                         `recordid` int(10) unsigned NOT NULL auto_increment,
00077                         PRIMARY KEY  (`recordid`)
00078                     ) ENGINE=MyISAM;
00079                    ");
00080 
00081         $db->Execute("insert into children (person_id,name_first,name_last,favorite_pet) values (1,'Jill','Lim','tortoise')");
00082         $db->Execute("insert into children (person_id,name_first,name_last) values (1,'Joan','Lim')");
00083         $db->Execute("insert into children (person_id,name_first,name_last) values (1,'JAMIE','Lim')");
00084                            
00085         $db->Execute("insert into artists (artistuniqueid, name) values(1,'Elvis Costello')");
00086         $db->Execute("insert into songs (recordid, name, artistid) values(1,'No Hiding Place', 1)");
00087         $db->Execute("insert into songs (recordid, name, artistid) values(2,'American Gangster Time', 1)");
00088 
00089         // This class _implicitely_ relies on the 'people' table (pluralized form of 'person')
00090         class Person extends ADOdb_Active_Record
00091         {
00092                 function __construct()
00093                 {
00094                         parent::__construct();
00095                         $this->hasMany('children');
00096                 }
00097         }
00098         // This class _implicitely_ relies on the 'children' table
00099         class Child extends ADOdb_Active_Record
00100         {
00101                 function __construct()
00102                 {
00103                         parent::__construct();
00104                         $this->belongsTo('person');
00105                 }
00106         }
00107         // This class _explicitely_ relies on the 'children' table and shares its metadata with Child
00108         class Kid extends ADOdb_Active_Record
00109         {
00110                 function __construct()
00111                 {
00112                         parent::__construct('children');
00113                         $this->belongsTo('person');
00114                 }
00115         }
00116         // This class _explicitely_ relies on the 'children' table but does not share its metadata
00117         class Rugrat extends ADOdb_Active_Record
00118         {
00119                 function __construct()
00120                 {
00121                         parent::__construct('children', false, false, array('new' => true));
00122                 }
00123         }
00124         
00125         class Artist extends ADOdb_Active_Record
00126         {
00127                 function __construct()
00128                 {
00129                         parent::__construct('artists', array('artistuniqueid'));
00130                         $this->hasMany('songs', 'artistid');
00131                 }
00132         }
00133         class Song extends ADOdb_Active_Record
00134         {
00135                 function __construct()
00136                 {
00137                         parent::__construct('songs', array('recordid'));
00138                         $this->belongsTo('artist', 'artistid');
00139                 }
00140         }
00141 
00142         ar_echo("Inserting person in 'people' table ('John Lim, he likes lavender')\n");
00143         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00144         $person = new Person();
00145         $person->name_first     = 'John';
00146         $person->name_last      = 'Lim';
00147         $person->favorite_color = 'lavender';
00148         $person->save(); // this save will perform an INSERT successfully
00149 
00150         $person = new Person();
00151         $person->name_first             = 'Lady';
00152         $person->name_last              = 'Cat';
00153         $person->favorite_color = 'green';
00154         $person->save();
00155         
00156         $child = new Child();
00157         $child->name_first              = 'Fluffy';
00158         $child->name_last               = 'Cat';
00159         $child->favorite_pet    = 'Cat Lady';
00160         $child->person_id               = $person->id;
00161         $child->save();
00162         
00163         $child = new Child();
00164         $child->name_first              = 'Sun';
00165         $child->name_last               = 'Cat';
00166         $child->favorite_pet    = 'Cat Lady';
00167         $child->person_id               = $person->id;
00168         $child->save();
00169         
00170         $err_count = 0;
00171 
00172         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00173         ar_echo("person->Find('id=1') [Lazy Method]\n");
00174         ar_echo("person is loaded but its children will be loaded on-demand later on\n");
00175         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00176         $person = new Person();
00177         $people = $person->Find('id=1');
00178         ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
00179         ar_echo((ar_assert(notfound($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00180         ar_echo("\n-- Lazily Loading Children:\n\n");
00181         foreach($people as $aperson)
00182         {
00183                 foreach($aperson->children as $achild)
00184                 {
00185                         if($achild->name_first);
00186                 }
00187         }
00188         ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
00189         ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
00190         ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
00191 
00192         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00193         ar_echo("person->Find('id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00194         ar_echo("person is loaded, and so are its children\n");
00195         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00196         $person = new Person();
00197         $people = $person->Find('id=1', false, false, array('loading' => ADODB_WORK_AR));
00198         ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
00199         ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
00200         ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
00201         ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
00202 
00203         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00204         ar_echo("person->Find('id=1' ... ADODB_JOIN_AR) [Join Method]\n");
00205         ar_echo("person and its children are loaded using a single query\n");
00206         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00207         $person = new Person();
00208         // When I specifically ask for a join, I have to specify which table id I am looking up
00209         // otherwise the SQL parser will wonder which table's id that would be.
00210         $people = $person->Find('people.id=1', false, false, array('loading' => ADODB_JOIN_AR));
00211         ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
00212         ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
00213         ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
00214         ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
00215                 
00216         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00217         ar_echo("person->Load('people.id=1') [Join Method]\n");
00218         ar_echo("Load() always uses the join method since it returns only one row\n");
00219         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00220         $person = new Person();
00221         // Under the hood, Load(), since it returns only one row, always perform a join
00222         // Therefore we need to clarify which id we are talking about.
00223         $person->Load('people.id=1');
00224         ar_echo((ar_assert(found($person, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
00225         ar_echo((ar_assert(found($person, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
00226         ar_echo((ar_assert(found($person, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
00227         ar_echo((ar_assert(found($person, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
00228         
00229         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00230         ar_echo("child->Load('children.id=1') [Join Method]\n");
00231         ar_echo("We are now loading from the 'children' table, not from 'people'\n");
00232         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00233         $child = new Child();
00234         $child->Load('children.id=1');
00235         ar_echo((ar_assert(found($child, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00236         ar_echo((ar_assert(found($child, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
00237 
00238         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00239         ar_echo("child->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00240         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00241         $child = new Child();
00242         $children = $child->Find('id=1', false, false, array('loading' => ADODB_WORK_AR));
00243         ar_echo((ar_assert(found($children, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00244         ar_echo((ar_assert(found($children, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
00245         ar_echo((ar_assert(notfound($children, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Find failed\n");
00246         ar_echo((ar_assert(notfound($children, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Find failed\n");
00247 
00248         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00249         ar_echo("kid->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00250         ar_echo("Where we see that kid shares relationships with child because they are stored\n");
00251         ar_echo("in the common table's metadata structure.\n");
00252         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00253         $kid = new Kid('children');
00254         $kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
00255         ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00256         ar_echo((ar_assert(found($kids, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
00257         ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Find failed\n");
00258         ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Find failed\n");
00259 
00260         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00261         ar_echo("kid->Find('children.id=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
00262         ar_echo("Of course, lazy loading also retrieve medata information...\n");
00263         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00264         $kid = new Kid('children');
00265         $kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_LAZY_AR));
00266         ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00267         ar_echo((ar_assert(notfound($kids, "'favorite_color' => 'lavender'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00268         ar_echo("\n-- Lazily Loading People:\n\n");
00269         foreach($kids as $akid)
00270         {
00271                 if($akid->person);
00272         }
00273         ar_echo((ar_assert(found($kids, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
00274         ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
00275         ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
00276         
00277         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00278         ar_echo("rugrat->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00279         ar_echo("In rugrat's constructor it is specified that\nit must forget any existing relation\n");
00280         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00281         $rugrat = new Rugrat('children');
00282         $rugrats = $rugrat->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
00283         ar_echo((ar_assert(found($rugrats, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00284         ar_echo((ar_assert(notfound($rugrats, "'favorite_color' => 'lavender'"))) ? "[OK] No relation found\n" : "[!!] Found relation when I shouldn't\n");
00285         ar_echo((ar_assert(notfound($rugrats, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
00286         ar_echo((ar_assert(notfound($rugrats, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
00287         
00288         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00289         ar_echo("kid->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00290         ar_echo("Note how only rugrat forgot its relations - kid is fine.\n");
00291         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00292         $kid = new Kid('children');
00293         $kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
00294         ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00295         ar_echo((ar_assert(found($kids, "'favorite_color' => 'lavender'"))) ? "[OK] I did not forget relation: person\n" : "[!!] I should not have forgotten relation: person\n");
00296         ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
00297         ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
00298         
00299         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00300         ar_echo("rugrat->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
00301         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00302         $rugrat = new Rugrat('children');
00303         $rugrats = $rugrat->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
00304         $arugrat = $rugrats[0];
00305         ar_echo((ar_assert(found($arugrat, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00306         ar_echo((ar_assert(notfound($arugrat, "'favorite_color' => 'lavender'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00307         
00308         ar_echo("\n-- Loading relations:\n\n");
00309         $arugrat->belongsTo('person');
00310         $arugrat->LoadRelations('person', 'order by id', 0, 2);
00311         ar_echo((ar_assert(found($arugrat, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
00312         ar_echo((ar_assert(found($arugrat, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
00313         ar_echo((ar_assert(notfound($arugrat, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
00314         ar_echo((ar_assert(notfound($arugrat, "'name_first' => 'JAMIE'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
00315 
00316         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00317         ar_echo("person->Find('1=1') [Lazy Method]\n");
00318         ar_echo("And now for our finale...\n");
00319         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00320         $person = new Person();
00321         $people = $person->Find('1=1', false, false, array('loading' => ADODB_LAZY_AR));
00322         ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
00323         ar_echo((ar_assert(notfound($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00324         ar_echo((ar_assert(notfound($people, "'name_first' => 'Fluffy'"))) ? "[OK] No Fluffy yet\n" : "[!!] Found Fluffy relation when I shouldn't\n");
00325         ar_echo("\n-- Lazily Loading Everybody:\n\n");
00326         foreach($people as $aperson)
00327         {
00328                 foreach($aperson->children as $achild)
00329                 {
00330                         if($achild->name_first);
00331                 }
00332         }
00333         ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
00334         ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
00335         ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
00336         ar_echo((ar_assert(found($people, "'name_first' => 'Lady'"))) ? "[OK] Found Cat Lady\n" : "[!!] Find failed\n");
00337         ar_echo((ar_assert(found($people, "'name_first' => 'Fluffy'"))) ? "[OK] Found Fluffy\n" : "[!!] Find failed\n");
00338         ar_echo((ar_assert(found($people, "'name_first' => 'Sun'"))) ? "[OK] Found Sun\n" : "[!!] Find failed\n");
00339         
00340         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00341         ar_echo("artist->Load('artistuniqueid=1') [Join Method]\n");
00342         ar_echo("Yes, we are dabbling in the musical field now..\n");
00343         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00344         $artist = new Artist();
00345         $artist->Load('artistuniqueid=1');
00346         ar_echo((ar_assert(found($artist, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
00347         ar_echo((ar_assert(found($artist, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
00348 
00349 
00350         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00351         ar_echo("song->Load('recordid=1') [Join Method]\n");
00352         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00353         $song = new Song();
00354         $song->Load('recordid=1');
00355         ar_echo((ar_assert(found($song, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
00356 
00357         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00358         ar_echo("artist->Find('artistuniqueid=1' ... ADODB_JOIN_AR) [Join Method]\n");
00359         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00360         $artist = new Artist();
00361         $artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_JOIN_AR));
00362         ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
00363         ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
00364 
00365         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00366         ar_echo("song->Find('recordid=1' ... ADODB_JOIN_AR) [Join Method]\n");
00367         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00368         $song = new Song();
00369         $songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_JOIN_AR));
00370         ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
00371 
00372         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00373         ar_echo("artist->Find('artistuniqueid=1' ... ADODB_WORK_AR) [Work Method]\n");
00374         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00375         $artist = new Artist();
00376         $artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_WORK_AR));
00377         ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
00378         ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
00379 
00380         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00381         ar_echo("song->Find('recordid=1' ... ADODB_JOIN_AR) [Join Method]\n");
00382         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00383         $song = new Song();
00384         $songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_WORK_AR));
00385         ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
00386 
00387         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00388         ar_echo("artist->Find('artistuniqueid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
00389         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00390         $artist = new Artist();
00391         $artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_LAZY_AR));
00392         ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
00393         ar_echo((ar_assert(notfound($artists, "'name' => 'No Hiding Place'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00394         foreach($artists as $anartist)
00395         {
00396                 foreach($anartist->songs as $asong)
00397                 {
00398                         if($asong->name);
00399                 }
00400         }
00401         ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
00402 
00403         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00404         ar_echo("song->Find('recordid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
00405         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00406         $song = new Song();
00407         $songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_LAZY_AR));
00408         ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
00409         ar_echo((ar_assert(notfound($songs, "'name' => 'Elvis Costello'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
00410         foreach($songs as $asong)
00411         {
00412                 if($asong->artist);
00413         }
00414         ar_echo((ar_assert(found($songs, "'name' => 'Elvis Costello'"))) ? "[OK] Found relation: artist\n" : "[!!] Missing relation: artist\n");
00415 
00416         ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
00417         ar_echo("Test suite complete. " . (($err_count > 0) ? "$err_count errors found.\n" : "Success.\n"));
00418         ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
00419 ?>