colour = 'red'; $red->save(); $green = new Stapler(); $green->colour = 'green'; $green->save(); $michal->staplers->add($red); $green->users->add($michal); $db->execute('SELECT * FROM employees_to_staplers'); $count = 0; foreach ($db as $row) { ++$count; } echo "Cross-assigning Staplers to Employees: " . (($count == 2) ? 'PASSED' : 'FAILED') . "\n"; $count = 0; foreach ($michal->staplers as $s) { ++$count; } echo "Accessing Staplers via many-to-many relation: " . (($count == 2) ? 'PASSED' : 'FAILED') . "\n"; $patry->staplers->add($red); $green->users->add($patry); $green->users->remove($michal); $count = 0; foreach ($patry->staplers as $s) { ++$count; } echo "Checking Staplers in object Employee after removing one Stapler from different Employee: " . (($count == 2) ? 'PASSED' : 'FAILED') . "\n"; $green->users->remove($patry); $patry->staplers->remove($red); $michal->staplers->remove($red); $count = 0; foreach ($patry->staplers as $s) { ++$count; } echo "Removing all Staplers to Employees relations: " . (!$count ? 'PASSED' : 'FAILED') . "\n"; ?>