getTableForeignKey example

$query->execute();
    }

    /** * @param string $table * @param array $data * @param int|string $foreignKey */
    private function create($table$data$foreignKey)
    {
        $query = $this->connection->createQueryBuilder();
        $foreignKeyColumn = $this->mapping->getTableForeignKey($table);

        $data[$foreignKeyColumn] = $foreignKey;
        $query->insert($table);
        foreach ($data as $key => $value) {
            $query->setValue($key, ':' . $key);
            $query->setParameter(':' . $key$value);
        }
        $query->execute();
    }

    /** * Updates an existing attribute * * @param string $table * @param array $data * @param int|string $foreignKey */

    public function load($table$foreignKey)
    {
        if (!$this->mapping->isAttributeTable($table)) {
            throw new Exception(sprintf('Table %s is no attribute table', $table));
        }

        if (!$foreignKey) {
            throw new Exception('No foreign key provided');
        }

        $foreignKeyColumn = $this->mapping->getTableForeignKey($table);

        $query = $this->connection->createQueryBuilder();
        $query->select('alias.*')
            ->from($table, 'alias')
            ->where('alias.' . $foreignKeyColumn . ' = :foreignKey')
            ->setParameter(':foreignKey', $foreignKey)
            ->setFirstResult(0)
            ->setMaxResults(1);

        return $query->execute()->fetch(PDO::FETCH_ASSOC) ?: [];
    }

    
Home | Imprint | This part of the site doesn't use cookies.