Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

unknown column when clicking tag

carlokokcarlokok New
edited September 2011 in Vanilla 2.0 - 2.8
After updating to 2.0.18b4 (2.0.18 branch on github) I'm getting the following error when clicking a tag, what am I missing?


Unknown column 'd.DiscussionID' in 'on clause' select c.*, lc.DateInserted as `DateLastComment` from GDN_Category c join GDN_TagDiscussion td on d.DiscussionID = td.DiscussionID left join GDN_Comment lc on c.LastCommentID = lc.CommentID where td.TagID in ('37') order by c.TreeLeft asc limit 50 /connect/library/database/class.database.phpPHP::Gdn_ErrorHandler(); [/connect/library/database/class.database.php:287] PHP::trigger_error(); [/connect/library/database/class.sqldriver.php:1650] Gdn_Database->Query(); [/connect/library/database/class.sqldriver.php:676] Gdn_SQLDriver->Query(); [/connect/applications/vanilla/models/class.categorymodel.php:90] Gdn_SQLDriver->Get(); [/connect/applications/vanilla/models/class.discussionmodel.php:445] CategoryModel::Categories(); [/connect/applications/vanilla/models/class.discussionmodel.php:55] DiscussionModel::CategoryPermissions(); [/connect/applications/vanilla/models/class.discussionmodel.php:136] DiscussionModel->DiscussionSummaryQuery(); [/connect/plugins/Tagging/class.tagging.plugin.php:106] DiscussionModel->Get(); [/connect/library/core/class.pluginmanager.php:713] TaggingPlugin->DiscussionsController_Tagged_Create(); [/connect/library/core/class.dispatcher.php:313] Gdn_PluginManager->CallNewMethod(); [/connect/index.php:53] Gdn_Dispatcher->Dispatch();
Tagged:

Answers

  • Looks like I'm getting the same at http://causes.autostatic.vanillaforums.com/discussions/tagged/abuse/p1/feed.rss

    (no idea what that is, it showed up on google when searching for the error)
  • Could you do a favor and open :
    applications/vanilla/models/class.categorymodel.php
    go to line 90
    Then copy and paste the Get() function in this thread please?
  • at line 90 I have:

    public static function Categories($ID = FALSE) {
    if (self::$Categories == NULL) {
    // Try and get the categories from the cache.
    $Categories = Gdn::Cache()->Get(self::CACHE_KEY);

    if (!$Categories) {
    $Sql = Gdn::SQL();
    $Sql = clone $Sql;
    $Session = Gdn::Session();

    $Sql->Select('c.*')
    ->Select('lc.DateInserted', '', 'DateLastComment')
    ->From('Category c')
    ->Join('Comment lc', 'c.LastCommentID = lc.CommentID', 'left')
    ->OrderBy('c.TreeLeft');

    $Categories = array_merge(array(), $Sql->Get()->ResultArray());
    $Categories = Gdn_DataSet::Index($Categories, 'CategoryID');
    self::CalculateData($Categories);
    Gdn::Cache()->Store(self::CACHE_KEY, $Categories, array(Gdn_Cache::FEATURE_EXPIRY => 600));
    }

    self::JoinUserData($Categories, TRUE);

    self::$Categories = $Categories;
    }

    if ($ID !== FALSE) {
    if (!is_numeric($ID) && $ID) {
    foreach (self::$Categories as $Category) {
    if ($Category['UrlCode'] == $ID)
    $ID = $Category['CategoryID'];
    }
    }

    if (isset(self::$Categories[$ID])) {
    $Result = self::$Categories[$ID];
    return $Result;
    } else {
    return NULL;
    }
    } else {
    $Result = self::$Categories;
    return $Result;
    }
    }

    The get function around 340 looks like:

    public function Get($OrderFields = '', $OrderDirection = 'asc', $Limit = FALSE, $Offset = FALSE) {
    $this->SQL
    ->Select('c.ParentCategoryID, c.CategoryID, c.TreeLeft, c.TreeRight, c.Depth, c.Name, c.Description, c.CountDiscussions, c.AllowDiscussions, c.UrlCode')
    ->From('Category c')
    ->BeginWhereGroup()
    ->Permission('Vanilla.Discussions.View', 'c', 'PermissionCategoryID', 'Category')
    ->EndWhereGroup()
    ->OrWhere('AllowDiscussions', '0')
    ->OrderBy('TreeLeft', 'asc');

    // Note: we are using the Nested Set tree model, so TreeLeft is used for sorting.
    // Ref: http://articles.sitepoint.com/article/hierarchical-data-database/2
    // Ref: http://en.wikipedia.org/wiki/Nested_set_model

    $CategoryData = $this->SQL->Get();
    $this->AddCategoryColumns($CategoryData);
    return $CategoryData;
    }

  • UnderDogUnderDog MVP
    edited September 2011
    Oh boy...
    There's a plugin called the Tagging plugin. In the event that's executed before the Get() function (which is strange, but ok...) you will have this function:
    public function DiscussionModel_BeforeGet_Handler($Sender) { if (C('Plugins.Tagging.Enabled') && property_exists($Sender, 'FilterToTagID')) $Sender->SQL->Join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID and td.TagID = '.$Sender->FilterToTagID); }I will look further if there's another piece of code with the tagDiscussion table, but it looks like this piece of code gives the troubles.

    By the way... the piece of code isn't wrong it just doesn't belong in the query that you showed in the original error.
    Also... I see that you're requesting for a specific tag. That's good for the problem description, once this will be registered as a bug.
  • so what can I do to get around this issue?
  • carlokokcarlokok New
    edited October 2011
    Any suggestions on how to get around this, a possible fix, or a place to look for a fix would be appreciated.

    http://screencast.com/t/60wsIqGpDQ << video

    The plugin used here is: https://github.com/vanillaforums/Garden/tree/master/plugins/Tagging
  • x00x00 MVP
    edited October 2011
    @UnderDog there is nothing strange about using BeforeGet you are hardly going to add the join after the result is returned unless de-normalised.

    @carlokok You may have an incompatable veriosn of tagging, what is the contents of
    DiscussionsController_Tagged_Create do you have 'FilterToTagIDs' there and in DiscussionModel_BeforeGet_Handler?

    Something has gone wrong somewhere, becuase in my version there is not Join with Tag, instead that is called separately to get the TagIDs then that is used to get the data from the model. I think you are using the wrong version of tagging.

    grep is your friend.

  • @x00: No "FilterToTagIDS", I'm using vanilla master with Tagging master (ie:
    https://github.com/vanillaforums/Garden/blob/master/plugins/Tagging/class.tagging.plugin.php
    )

    I noticed this doesn't happen all the time. 1 colleague can reproduce it in IE but not Chrome; I had it in chrome the other day but it doesn't show now; it's like it depends on a specific option or origin or something.
  • well GDN_Category c doesn't make sense becuase the category data should be de-normalised in that version of vanilla.

    grep is your friend.

  • x00x00 MVP
    edited October 2011
    I use the TaggingEnhanced plugin. Which has the FilterByTags method. Although it is modded to suit my needs. Weirdly it uses the the DiscussionModel object to do the tag query. Although it works fine inheriting those properties from Gdn_Model, I used Gnd::SQL() as better form, and to save confusion with the discussion model that is used legitimately, and possible impurity.

    I think it is better becuase it doesn't rely on joins. Query can be build with additions from multiple plugins, you can end up with quite a monstrosity of a query. That might be what is happening here. I tend to stick to wheres and the like, only doing joins where absolutely necessary.

    grep is your friend.

Sign In or Register to comment.