atk4\data\tests\JoinArrayTest::testJoinSaving2 PHP Method

testJoinSaving2() public method

public testJoinSaving2 ( )
    public function testJoinSaving2()
    {
        $a = ['user' => [], 'contact' => []];
        $db = new Persistence_Array($a);
        $m_u = new Model($db, 'user');
        $m_u->addField('name');
        $j = $m_u->join('contact.test_id');
        $j->addField('contact_phone');
        $m_u['name'] = 'John';
        $m_u['contact_phone'] = '+123';
        $m_u->save();
        $this->assertEquals(['user' => [1 => ['id' => 1, 'name' => 'John']], 'contact' => [1 => ['id' => 1, 'test_id' => 1, 'contact_phone' => '+123']]], $a);
        $m_u->unload();
        $m_u['name'] = 'Peter';
        $m_u->save();
        $this->assertEquals(['user' => [1 => ['id' => 1, 'name' => 'John'], 2 => ['id' => 2, 'name' => 'Peter']], 'contact' => [1 => ['id' => 1, 'test_id' => 1, 'contact_phone' => '+123'], 2 => ['id' => 2, 'test_id' => 2, 'contact_phone' => null]]], $a);
        unset($a['contact'][2]);
        $m_u->unload();
        $m_u['name'] = 'Sue';
        $m_u['contact_phone'] = '+444';
        $m_u->save();
        $this->assertEquals(['user' => [1 => ['id' => 1, 'name' => 'John'], 2 => ['id' => 2, 'name' => 'Peter'], 3 => ['id' => 3, 'name' => 'Sue']], 'contact' => [1 => ['id' => 1, 'test_id' => 1, 'contact_phone' => '+123'], 2 => ['id' => 2, 'test_id' => 3, 'contact_phone' => '+444']]], $a);
    }