/** * Process query with joined data * @param object $row One row of data * @return Database */ protected function join($row) { $keys['local'] = $this->keys['local']; $keys['foreign'] = $this->keys['foreign']; if ($this->relationType == 'hasAndBelongsToMany') { $join = Database::table($this->getJunction())->groupBy($this->tables['local'] . '_id')->where($this->tables['local'] . '_id', '=', $row->{$keys['local']})->findAll()->asArray(null, $this->tables['foreign'] . '_id'); if (empty($join)) { return array(); } return Database::table($this->tables['foreign'])->where($keys['foreign'], 'IN', $join[$row->{$keys['local']}]); } return Database::table($this->tables['foreign'])->where($keys['foreign'], '=', $row->{$keys['local']}); }