phpsqlpostgresqlbolt-cms

The entry on SQL it's being recognized as column


I'm trying to use the extension RelatedContentByTags, but the entry on bolt_taxonomy column it's being recognized as column.

I have this error when I put {{ relatedcontentbytags(record) }} on index.

'Twig_Error_Runtime thrown with message
"An exception has been thrown during the rendering of a template
("An exception occurred while executing ' SELECT bolt_entries.id FROM bolt_entries LEFT JOIN 
bolt_taxonomy ON bolt_entries.id = bolt_taxonomy.content_id WHERE
bolt_entries.status = "published"AND bolt_entries.id != 3 AND
bolt_taxonomy.contenttype = "entries" AND (bolt_taxonomy.taxonomytype = "tags" AND 
(bolt_taxonomy.slug = "teste2"))':

SQLSTATE[42703]: Undefined column: 7 ERROR:  column "published" does not exist
LINE 1: ...t_taxonomy.content_id WHERE bolt_entries.status = "published...^") in "entry.twig" at line 65."

And the extension.php is that:

$results = array();
        foreach ($tables as $name) {

            $table        = sprintf('%s%s', $tablePrefix, $name);
            $querySelect  = '';
            $querySelect .= sprintf(' SELECT %s.id FROM %s', $table, $table);
            $querySelect .= sprintf(' LEFT JOIN %s', $taxonomyTable);
            $querySelect .= sprintf(' ON %s.id = %s.content_id', $table, $taxonomyTable);
            $querySelect .= sprintf(' WHERE %s.status = "published"', $table);
            if ($name == $record->contenttype['slug']) {
                $querySelect .= sprintf('AND %s.id != '. $record->id, $table);
            }
            $querySelect .= sprintf(' AND %s.contenttype = "%s"', $taxonomyTable, $name);
            $querySelect .= sprintf(' AND (%s)', $queryWhere);

            $queryResults = $app['db']->fetchAll( $querySelect );

            if (!empty($queryResults)) {
                $ids      = implode(' || ', \utilphp\util::array_pluck($queryResults, 'id'));
                $contents = $app['storage']->getContent($name, array('id' => $ids, 'returnsingle' => false));
                $results  = array_merge( $results,  $contents );
            }
        }

Solution

  • Depending on what database you are using (I'm guessing Postgresql based on the error code) text enclosed in double-quotes "" can be used to denote a table name; single-quotes '' are normally used to denote character literals, so try changing "published" to 'published' (the same goes for entries, tags, and teste2 too of course).