Sokil\Mongo\DocumentRelationTest::testGetRelated_HasMany PHP Метод

testGetRelated_HasMany() публичный Метод

A -> HAS_MANY -> B
    public function testGetRelated_HasMany()
    {
        // collections
        $carsCollection = $this->database->getCollection('cars');
        $wheelsCollection = $this->database->getCollection('wheels');
        // add documents
        $carDocument = $carsCollection->createDocument(array('param' => 'value'))->save();
        // add target documents
        $wheelDocument1 = $wheelsCollection->createDocument(array('car_id' => $carDocument->getId()))->save();
        // add target document
        $wheelDocument2 = $wheelsCollection->createDocument(array('car_id' => $carDocument->getId()))->save();
        // test
        $this->assertArrayHasKey((string) $wheelDocument1->getId(), $carDocument->wheels);
        $this->assertArrayHasKey((string) $wheelDocument2->getId(), $carDocument->wheels);
    }