• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

liqueurdetoile / cakephp-orm-json / 3816986970

pending completion
3816986970

Pull #11

github

GitHub
Merge 5277f4d4a into 6364490a4
Pull Request #11: ci: Fix phinx update issue

898 of 1015 relevant lines covered (88.47%)

43.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/src/ORM/Association/Loader/DatFieldSelectWithPivotLoader.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Lqdt\OrmJson\ORM\Association\Loader;
5

6
use Cake\ORM\Association\Loader\SelectWithPivotLoader;
7
use Lqdt\OrmJson\DatField\DatFieldParserTrait;
8

9
class DatFieldSelectWithPivotLoader extends SelectWithPivotLoader
10
{
11
    use DatFieldParserTrait;
12

13
    /**
14
     * @inheritDoc
15
     */
16
    protected function _buildResultMap($fetchQuery, $options): array
17
    {
18
        $resultMap = [];
5✔
19
        $key = (array)$options['foreignKey'];
5✔
20

21
        // We must fetch the right alias for foreign key to match data correctly when key is selected
22
        $select = array_flip($fetchQuery->clause('select'));
5✔
23
        $key = array_map(function ($k) use ($fetchQuery, $select) {
5✔
24
            if ($this->isDatField($k)) {
5✔
25
                if (empty($this->getDatFieldPart('model', $k))) {
5✔
26
                    $k = $fetchQuery->getRepository()->getAlias() . '.' . $k;
5✔
27
                }
28

29
                if (is_int($select[$k] ?? false)) {
5✔
30
                    $select[$k] = $this->aliasDatField($k);
×
31
                }
32
            }
33

34
            return $select[$k] ?? $k;
5✔
35
        }, $key);
5✔
36

37
        foreach ($fetchQuery->all() as $result) {
5✔
38
            if (!isset($result[$this->junctionProperty])) {
5✔
39
                throw new \RuntimeException(sprintf(
×
40
                    '"%s" is missing from the belongsToMany results. Results cannot be created.',
×
41
                    $this->junctionProperty
×
42
                ));
×
43
            }
44

45
            $values = [];
5✔
46
            foreach ($key as $k) {
5✔
47
                $values[] = $this->getDatFieldValueInData($k, $result[$this->junctionProperty]);
5✔
48
            }
49
            $resultMap[implode(';', $values)][] = $result;
5✔
50
        }
51

52
        return $resultMap;
5✔
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc