Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Silverstripe 2.4 - 3.1 Upgrade - innerJoin 'unknown column' issue


Go to End


1196 Views

Avatar
manueltomasir

Community Member, 1 Post

4 February 2015 at 9:54am

Edited: 04/02/2015 9:57am

I am trying to update a website from SS 2.4 to SS 3.1 and have been digging around the web on this issue for a while now.

The old code looks like this...

return DataObject::get('SupportItem', "SupportItemType = '$itemType' AND ProductPageID = $productID", null, 'INNER JOIN SupportItem_Products ON SupportItem_Products.SupportItemID = SupportItem.ID');

I am trying to switch out of the deprecated INNER JOIN and DataObject::get to the now current innerJoin and DataobjectName::get. This is what I have for the new code

$productID = $this->productToView->ID;
return SupportProductListingPage::get()->innerJoin('SupportItem_Products', '"SupportItem_Products"."SupportItemID" = "SupportItem"."ID"', null)->filter(array('SupportItemType'=>'$itemType', 'ProductPageID' => '$productID'));

It should be noted that the "SupportItemID" column exists in "SupportItem_Products" and the "ID" column exists in "SupportItem". However, "SupportItemID" does not exist in the "SupportItem" table.

I am receiving the below error when loading the page...

[User Error] Couldn't run query: SELECT DISTINCT count(DISTINCT "SiteTree"."ID") AS "0" FROM "SiteTree" LEFT JOIN "Page" ON "Page"."ID" = "SiteTree"."ID" INNER JOIN "SupportItem_Products" ON "SupportItem_Products"."SupportItemID" = "SupportItem"."ID" WHERE ("ProductPageID" = '$productID') AND ("SiteTree"."ClassName" IN ('SupportProductListingPage')) Unknown column 'SupportItem.ID' in 'on clause'

Can anyone help?