Jump to content

Ambigious column in order clause, \IPS\Helpers\Table\Content


TSP

Recommended Posts

Posted

Hi, 

I try to use \IPS\Helpers\Table\Content, but I encounter this error when trying to do so with joinComments set to true. 

SELECT forums_topics.tid FROM `b5dev_forums_topics` AS `forums_topics`  LEFT JOIN `b5dev_forums_forums` AS `forums_forums` ON ( forums_forums.password IS NULL OR ( FIND_IN_SET(4,forums_forums.password_override) ) ) AND forums_forums.min_posts_view<=3 AND forums_topics.forum_id=forums_forums.id  LEFT JOIN `b5dev_forums_posts` AS `forums_posts` ON forums_posts.topic_id=forums_topics.tid WHERE forums_posts.author_id=1 AND forums_topics.last_post > 1473811200 AND forums_topics.approved < 2 AND forums_topics.approved!=-2 AND ( NULLIF(forums_topics.moved_to, '') IS NULL ) AND forums_topics.forum_id IN(1,2,3) GROUP BY `tid` ORDER BY last_post desc LIMIT 0,25
IPS\Db\Exception: Column 'last_post' in order clause is ambiguous (1052)
#0 /*/init.php(448) : eval()'d code(129): IPS\_Db->preparedQuery('/*IPS\\storm_hoo...', Array, true)
#1 /*/system/Db/Select.php(378): IPS\storm_hook_Db->preparedQuery('SELECT forums_t...', Array, true)
#2 /*/system/Db/Select.php(440): IPS\Db\_Select->runQuery()
#3 [internal function]: IPS\Db\_Select->rewind()
#4 /*/system/Content/Item.php(2612): iterator_to_array(Object(IPS\Db\Select))
#5 /*/applications/forums/sources/Topic/Topic.php(276): IPS\Content\_Item::getItemsWithPermission(Array, 'last_post desc', Array, 'view', true, 0, Object(IPS\Member), true, true, false, false, Array, false, true, true, true, false)
#6 /*/system/Helpers/Table/Content.php(287): IPS\forums\_Topic::getItemsWithPermission(Array, 'last_post desc', Array, 'view', NULL, 0, NULL, true, true, false, false, Array, false, true, true, true, false)
#7 /*/system/Helpers/Table/Table.php(480): IPS\Helpers\Table\_Content->getRows(Array)
#8 /*/test.php(8): IPS\Helpers\Table\_Table->__toString()
#9 {main}

I've created some simple code you can cut and paste into a file named test.php to see this for yourself: 

<?php
require_once 'init.php';
$disp = \IPS\Dispatcher\External::i();
$where[] = ['forums_posts.author_id=1'];
$where[] = ['forums_topics.last_post > 1473811200'];
$table  = new \IPS\Helpers\Table\Content( 'IPS\forums\Topic', \IPS\Http\Url::internal('app=myapp'), $where, NULL, NULL, 'view', FALSE );
$table->joinComments  = true;
echo $table . "\n";

I think you need to change system/Helpers/Table/Content.php around line 196-210. For example: 

			if ( isset( $class::$databaseColumnMap['updated'] ) )
			{
				$this->sortBy = $class::$databasePrefix . $class::$databaseColumnMap['updated'];
			}

I think $this->sortBy should have been prepended by: $class::$databaseTable . '.' .

 

Or am I doing something wrong here? 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...