1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
|
<?php
global $err_count;
$err_count = 0;
function found($obj, $cond)
{
$res = var_export($obj, true);
return (strpos($res, $cond));
}
function notfound($obj, $cond)
{
return !found($obj, $cond);
}
function ar_assert($bool)
{
global $err_count;
if(!$bool)
$err_count ++;
return $bool;
}
define('WEB', true);
function ar_echo($txt)
{
if(WEB)
$txt = str_replace("\n", "<br />\n", $txt);
echo $txt;
}
include_once('../adodb.inc.php');
include_once('../adodb-active-recordx.inc.php');
$db = NewADOConnection('mysql://root@localhost/test');
$db->debug=0;
ADOdb_Active_Record::SetDatabaseAdapter($db);
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("Preparing database using SQL queries (creating 'people', 'children')\n");
$db->Execute("DROP TABLE `people`");
$db->Execute("DROP TABLE `children`");
$db->Execute("DROP TABLE `artists`");
$db->Execute("DROP TABLE `songs`");
$db->Execute("CREATE TABLE `people` (
`id` int(10) unsigned NOT NULL auto_increment,
`name_first` varchar(100) NOT NULL default '',
`name_last` varchar(100) NOT NULL default '',
`favorite_color` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
$db->Execute("CREATE TABLE `children` (
`person_id` int(10) unsigned NOT NULL,
`name_first` varchar(100) NOT NULL default '',
`name_last` varchar(100) NOT NULL default '',
`favorite_pet` varchar(100) NOT NULL default '',
`id` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
");
$db->Execute("CREATE TABLE `artists` (
`name` varchar(100) NOT NULL default '',
`artistuniqueid` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`artistuniqueid`)
) ENGINE=MyISAM;
");
$db->Execute("CREATE TABLE `songs` (
`name` varchar(100) NOT NULL default '',
`artistid` int(10) NOT NULL,
`recordid` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`recordid`)
) ENGINE=MyISAM;
");
$db->Execute("insert into children (person_id,name_first,name_last,favorite_pet) values (1,'Jill','Lim','tortoise')");
$db->Execute("insert into children (person_id,name_first,name_last) values (1,'Joan','Lim')");
$db->Execute("insert into children (person_id,name_first,name_last) values (1,'JAMIE','Lim')");
$db->Execute("insert into artists (artistuniqueid, name) values(1,'Elvis Costello')");
$db->Execute("insert into songs (recordid, name, artistid) values(1,'No Hiding Place', 1)");
$db->Execute("insert into songs (recordid, name, artistid) values(2,'American Gangster Time', 1)");
// This class _implicitely_ relies on the 'people' table (pluralized form of 'person')
class Person extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct();
$this->hasMany('children');
}
}
// This class _implicitely_ relies on the 'children' table
class Child extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct();
$this->belongsTo('person');
}
}
// This class _explicitely_ relies on the 'children' table and shares its metadata with Child
class Kid extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct('children');
$this->belongsTo('person');
}
}
// This class _explicitely_ relies on the 'children' table but does not share its metadata
class Rugrat extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct('children', false, false, array('new' => true));
}
}
class Artist extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct('artists', array('artistuniqueid'));
$this->hasMany('songs', 'artistid');
}
}
class Song extends ADOdb_Active_Record
{
function __construct()
{
parent::__construct('songs', array('recordid'));
$this->belongsTo('artist', 'artistid');
}
}
ar_echo("Inserting person in 'people' table ('John Lim, he likes lavender')\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
$person->name_first = 'John';
$person->name_last = 'Lim';
$person->favorite_color = 'lavender';
$person->save(); // this save will perform an INSERT successfully
$person = new Person();
$person->name_first = 'Lady';
$person->name_last = 'Cat';
$person->favorite_color = 'green';
$person->save();
$child = new Child();
$child->name_first = 'Fluffy';
$child->name_last = 'Cat';
$child->favorite_pet = 'Cat Lady';
$child->person_id = $person->id;
$child->save();
$child = new Child();
$child->name_first = 'Sun';
$child->name_last = 'Cat';
$child->favorite_pet = 'Cat Lady';
$child->person_id = $person->id;
$child->save();
$err_count = 0;
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("person->Find('id=1') [Lazy Method]\n");
ar_echo("person is loaded but its children will be loaded on-demand later on\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
$people = $person->Find('id=1');
ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n-- Lazily Loading Children:\n\n");
foreach($people as $aperson)
{
foreach($aperson->children as $achild)
{
if($achild->name_first);
}
}
ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("person->Find('id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("person is loaded, and so are its children\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
$people = $person->Find('id=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("person->Find('id=1' ... ADODB_JOIN_AR) [Join Method]\n");
ar_echo("person and its children are loaded using a single query\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
// When I specifically ask for a join, I have to specify which table id I am looking up
// otherwise the SQL parser will wonder which table's id that would be.
$people = $person->Find('people.id=1', false, false, array('loading' => ADODB_JOIN_AR));
ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("person->Load('people.id=1') [Join Method]\n");
ar_echo("Load() always uses the join method since it returns only one row\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
// Under the hood, Load(), since it returns only one row, always perform a join
// Therefore we need to clarify which id we are talking about.
$person->Load('people.id=1');
ar_echo((ar_assert(found($person, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($person, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
ar_echo((ar_assert(found($person, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($person, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("child->Load('children.id=1') [Join Method]\n");
ar_echo("We are now loading from the 'children' table, not from 'people'\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$child = new Child();
$child->Load('children.id=1');
ar_echo((ar_assert(found($child, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($child, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("child->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$child = new Child();
$children = $child->Find('id=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($children, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($children, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
ar_echo((ar_assert(notfound($children, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($children, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("kid->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("Where we see that kid shares relationships with child because they are stored\n");
ar_echo("in the common table's metadata structure.\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$kid = new Kid('children');
$kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($kids, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("kid->Find('children.id=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
ar_echo("Of course, lazy loading also retrieve medata information...\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$kid = new Kid('children');
$kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($kids, "'favorite_color' => 'lavender'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n-- Lazily Loading People:\n\n");
foreach($kids as $akid)
{
if($akid->person);
}
ar_echo((ar_assert(found($kids, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("rugrat->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("In rugrat's constructor it is specified that\nit must forget any existing relation\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$rugrat = new Rugrat('children');
$rugrats = $rugrat->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($rugrats, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($rugrats, "'favorite_color' => 'lavender'"))) ? "[OK] No relation found\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($rugrats, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($rugrats, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("kid->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("Note how only rugrat forgot its relations - kid is fine.\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$kid = new Kid('children');
$kids = $kid->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($kids, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
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");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($kids, "'name_first' => 'JAMIE'"))) ? "[OK] No JAMIE relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("rugrat->Find('children.id=1' ... ADODB_WORK_AR) [Worker Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$rugrat = new Rugrat('children');
$rugrats = $rugrat->Find('children.id=1', false, false, array('loading' => ADODB_WORK_AR));
$arugrat = $rugrats[0];
ar_echo((ar_assert(found($arugrat, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($arugrat, "'favorite_color' => 'lavender'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n-- Loading relations:\n\n");
$arugrat->belongsTo('person');
$arugrat->LoadRelations('person', 'order by id', 0, 2);
ar_echo((ar_assert(found($arugrat, "'favorite_color' => 'lavender'"))) ? "[OK] Found relation: person\n" : "[!!] Missing relation: person\n");
ar_echo((ar_assert(found($arugrat, "'name_first' => 'Jill'"))) ? "[OK] Found Jill\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($arugrat, "'name_first' => 'Joan'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($arugrat, "'name_first' => 'JAMIE'"))) ? "[OK] No Joan relation\n" : "[!!] Found relation when I shouldn't\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("person->Find('1=1') [Lazy Method]\n");
ar_echo("And now for our finale...\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$person = new Person();
$people = $person->Find('1=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo((ar_assert(found($people, "'name_first' => 'John'"))) ? "[OK] Found John\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
ar_echo((ar_assert(notfound($people, "'name_first' => 'Fluffy'"))) ? "[OK] No Fluffy yet\n" : "[!!] Found Fluffy relation when I shouldn't\n");
ar_echo("\n-- Lazily Loading Everybody:\n\n");
foreach($people as $aperson)
{
foreach($aperson->children as $achild)
{
if($achild->name_first);
}
}
ar_echo((ar_assert(found($people, "'favorite_pet' => 'tortoise'"))) ? "[OK] Found relation: child\n" : "[!!] Missing relation: child\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Joan'"))) ? "[OK] Found Joan\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'JAMIE'"))) ? "[OK] Found JAMIE\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Lady'"))) ? "[OK] Found Cat Lady\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Fluffy'"))) ? "[OK] Found Fluffy\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($people, "'name_first' => 'Sun'"))) ? "[OK] Found Sun\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("artist->Load('artistuniqueid=1') [Join Method]\n");
ar_echo("Yes, we are dabbling in the musical field now..\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$artist = new Artist();
$artist->Load('artistuniqueid=1');
ar_echo((ar_assert(found($artist, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($artist, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("song->Load('recordid=1') [Join Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$song = new Song();
$song->Load('recordid=1');
ar_echo((ar_assert(found($song, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("artist->Find('artistuniqueid=1' ... ADODB_JOIN_AR) [Join Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$artist = new Artist();
$artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_JOIN_AR));
ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("song->Find('recordid=1' ... ADODB_JOIN_AR) [Join Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$song = new Song();
$songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_JOIN_AR));
ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("artist->Find('artistuniqueid=1' ... ADODB_WORK_AR) [Work Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$artist = new Artist();
$artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("song->Find('recordid=1' ... ADODB_JOIN_AR) [Join Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$song = new Song();
$songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_WORK_AR));
ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("artist->Find('artistuniqueid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$artist = new Artist();
$artists = $artist->Find('artistuniqueid=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo((ar_assert(found($artists, "'name' => 'Elvis Costello'"))) ? "[OK] Found Elvis Costello\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($artists, "'name' => 'No Hiding Place'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
foreach($artists as $anartist)
{
foreach($anartist->songs as $asong)
{
if($asong->name);
}
}
ar_echo((ar_assert(found($artists, "'name' => 'No Hiding Place'"))) ? "[OK] Found relation: song\n" : "[!!] Missing relation: song\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("song->Find('recordid=1' ... ADODB_LAZY_AR) [Lazy Method]\n");
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
$song = new Song();
$songs = $song->Find('recordid=1', false, false, array('loading' => ADODB_LAZY_AR));
ar_echo((ar_assert(found($songs, "'name' => 'No Hiding Place'"))) ? "[OK] Found song\n" : "[!!] Find failed\n");
ar_echo((ar_assert(notfound($songs, "'name' => 'Elvis Costello'"))) ? "[OK] No relation yet\n" : "[!!] Found relation when I shouldn't\n");
foreach($songs as $asong)
{
if($asong->artist);
}
ar_echo((ar_assert(found($songs, "'name' => 'Elvis Costello'"))) ? "[OK] Found relation: artist\n" : "[!!] Missing relation: artist\n");
ar_echo("\n\n-------------------------------------------------------------------------------------------------------------------\n");
ar_echo("Test suite complete. " . (($err_count > 0) ? "$err_count errors found.\n" : "Success.\n"));
ar_echo("-------------------------------------------------------------------------------------------------------------------\n");
|