public function testMultipleManyManysToTheSameModel() { $pp1 = new PP(); $pp1->name = 'pp1a'; $pp1->save(); $this->assertTrue($pp1->save()); $pp1Id = $pp1->id; $pp2 = new PP(); $pp2->name = 'pp2a'; $this->assertTrue($pp2->save()); $pp2Id = $pp2->id; $p = new P(); $p->name = 'manyNames'; $p->ppManyAssumptive->add($pp1); $p->ppManySpecific->add($pp2); $this->assertTrue($p->save()); $pId = $p->id; //Retrieve row to make sure columns are coppect $row = ZurmoRedBean::getRow('select * from p'); $this->assertCount(5, $row); $this->assertEquals(1, ZurmoRedBean::count('p_pp')); $row = ZurmoRedBean::getRow('select * from p_pp'); $this->assertTrue(isset($row['p_id']) && ($row['p_id'] = $p->id)); $this->assertTrue(isset($row['pp_id']) && ($row['pp_id'] = $pp1->id)); $this->assertCount(3, $row); $this->assertEquals(1, ZurmoRedBean::count('ppmanyspecificlink_p_pp')); $row = ZurmoRedBean::getRow('select * from ppmanyspecificlink_p_pp'); $this->assertTrue(isset($row['p_id']) && ($row['p_id'] = $p->id)); $this->assertTrue(isset($row['pp_id']) && ($row['pp_id'] = $pp2->id)); $this->assertCount(3, $row); //Unlink and make sure the tables are cleared $p->forget(); $pp1->forget(); $pp2->forget(); $p = P::getById($pId); $this->assertEquals(1, $p->ppManyAssumptive->count()); $this->assertEquals(1, $p->ppManySpecific->count()); $p->ppManyAssumptive->removeAll(); $p->ppManySpecific->removeAll(); $this->assertTrue($p->save()); $this->assertEquals(0, ZurmoRedBean::count('p_pp')); $this->assertEquals(0, ZurmoRedBean::count('ppmanyspecificlink_p_pp')); }