Code Duplication    Length = 13-13 lines in 2 locations

src/relationships/HasManyRelationship.php 1 location

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

src/relationships/BelongsToRelationship.php 1 location

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