Code Duplication    Length = 13-13 lines in 2 locations

src/relationships/BelongsToRelationship.php 1 location

@@ 41-53 (lines=13) @@
38
        $this->context = $context;
39
    }
40
41
    public function prepareQuery($data) {
42
        // @todo throw an exception when the data doesn't have the local key
43
        $query = $this->getQuery();
44
        if($this->queryPrepared){
45
            $query->setBoundData($this->options['foreign_key'], $data[$this->options['local_key']]);
46
        } else {
47
            $query->setTable($this->getModelInstance()->getDBStoreInformation()['quoted_table'])
48
                ->addFilter($this->options['foreign_key'], $data[$this->options['local_key']])
49
                ->setFirstOnly(true);
50
            $this->queryPrepared = true;
51
        }
52
        return $query;
53
    }
54
55
    public function runSetup() {
56
        $model = $this->container->resolve($this->context->getClassName($this->options['model'], self::BELONGS_TO));

src/relationships/HasManyRelationship.php 1 location

@@ 41-53 (lines=13) @@
38
        $this->context = $context;
39
    }
40
41
    public function prepareQuery($data) {
42
        // @todo throw an exception when the data doesn't have the local key
43
        $query = $this->getQuery();
44
        if ($this->queryPrepared) {
45
            $query->setBoundData($this->options['foreign_key'], $data[$this->options['local_key']]);
46
        } else {
47
            $query->setTable($this->getModelInstance()->getDBStoreInformation()['quoted_table'])
48
                    ->addFilter($this->options['foreign_key'], $data[$this->options['local_key']]);
49
            $this->queryPrepared = true;
50
        }
51
        return $query;
52
    }
53
54
    public function runSetup() {
55
        if ($this->options['foreign_key'] == null) {
56
            $this->options['foreign_key'] = Text::singularize($this->setupTable) . '_id';