Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] Ambiguous clause

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1130 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    [SOLVED] Ambiguous clause Link to this post

    Hi people,

    I'm having difficulty here with an ambiguous clause. I've searched the archives and forum and come across this problem but I'm none the wiser about what causes this, it's driving me nuts. Does anybody understand what causes this? I've tried a few different syntaxes but got no where with it. Help!

    <?php

    class FeaturedItemDropDown extends DataObjectDecorator{

       function extraStatics() {
    return array(
    'db' => array(
                'Summary' => 'Varchar(150)'
    ),
    'has_one' => array(
                'FeaturedImage' => 'Image'
    ),
    );
    }

       function updateCMSFields(FieldSet &$fields) {      
          $fields->addFieldToTab('Root.Content.Featured', new TextareaField('Summary', 'Summary (150 characters max)', '', 200));
          $fields->addFieldToTab('Root.Content.Featured', new ImageField('FeaturedImage', 'Upload your image (000 x 000)'));
       }

       public function RandomiseFeaturedItem($num = 1){
          return DataObject::get("sitetree", "`ParentID` = ".$this->owner->ID." AND `Summary` != 'NULL'", "RAND()", "", $num);
       }
    }

    The problem I have now is that the column 'Summary' in my database is ambiguous

    [User Error] Couldn't run query: SELECT "SiteTree_Live"."ClassName", "SiteTree_Live"."Created", "SiteTree_Live"."LastEdited", "SiteTree_Live"."URLSegment", "SiteTree_Live"."Title", "SiteTree_Live"."MenuTitle", "SiteTree_Live"."Content", "SiteTree_Live"."MetaTitle", "SiteTree_Live"."MetaDescription", "SiteTree_Live"."MetaKeywords", "SiteTree_Live"."ExtraMeta", "SiteTree_Live"."ShowInMenus", "SiteTree_Live"."ShowInSearch", "SiteTree_Live"."HomepageForDomain", "SiteTree_Live"."ProvideComments", "SiteTree_Live"."Sort", "SiteTree_Live"."HasBrokenFile", "SiteTree_Live"."HasBrokenLink", "SiteTree_Live"."Status", "SiteTree_Live"."ReportClass", "SiteTree_Live"."CanViewType", "SiteTree_Live"."CanEditType", "SiteTree_Live"."ToDo", "SiteTree_Live"."Version", "SiteTree_Live"."Summary", "SiteTree_Live"."ParentID", "SiteTree_Live"."FeaturedImageID", "SiteTree_Live"."SubsiteID", "SiteTree_Live"."MasterPageID", CASE WHEN "SiteTree_Live"."ClassName" IN ('HomePage') THEN "HomePage_Live"."ExtraDropNavInfo" WHEN "SiteTree_Live"."ClassName" IN ('LibraryHolder') THEN "LibraryHolder_Live"."ExtraDropNavInfo" ELSE NULL END AS "ExtraDropNavInfo", CASE WHEN "SiteTree_Live"."ClassName" IN ('HomePage') THEN "HomePage_Live"."ExtraDropNavInfoClassName" WHEN "SiteTree_Live"."ClassName" IN ('LibraryHolder') THEN "LibraryHolder_Live"."ExtraDropNavInfoClassName" ELSE NULL END AS "ExtraDropNavInfoClassName", "Library_Live"."LibraryHolderID", "BlogEntry_Live"."Date", "BlogEntry_Live"."Author", "BlogEntry_Live"."Tags", "BlogTree_Live"."Name", "BlogTree_Live"."InheritSideBar", "BlogTree_Live"."LandingPageFreshness", "BlogTree_Live"."SideBarID", "Calendar_Live"."DefaultEventDisplay", "Calendar_Live"."DefaultDateHeader", "Calendar_Live"."OtherDatesCount", "CalendarEvent_Live"."Recursion", "CalendarEvent_Live"."CustomRecursionType", "CalendarEvent_Live"."DailyInterval", "CalendarEvent_Live"."WeeklyInterval", "CalendarEvent_Live"."MonthlyInterval", "CalendarEvent_Live"."MonthlyRecursionType1", "CalendarEvent_Live"."MonthlyRecursionType2", "CalendarEvent_Live"."MonthlyIndex", "CalendarEvent_Live"."MonthlyDayOfWeek", "CalendarEvent_Live"."CalendarID", CASE WHEN "SiteTree_Live"."ClassName" IN ('ContactPage') THEN "ContactPage_Live"."Mailto" WHEN "SiteTree_Live"."ClassName" IN ('RegistrationForm') THEN "RegistrationForm_Live"."Mailto" ELSE NULL END AS "Mailto", "ContactPage_Live"."ContactSubmitText", "RegistrationForm_Live"."SubmitText", "GridPage_Live"."Template", "ErrorPage_Live"."ErrorCode", "RedirectorPage_Live"."RedirectionType", "RedirectorPage_Live"."ExternalURL", "RedirectorPage_Live"."LinkToID", "VirtualPage_Live"."VersionID", "VirtualPage_Live"."CopyContentFromID", "BlogHolder_Live"."TrackBacksEnabled", "BlogHolder_Live"."AllowCustomAuthors", "BlogHolder_Live"."OwnerID", "SubsitesVirtualPage_Live"."CustomMetaTitle", "SubsitesVirtualPage_Live"."CustomMetaKeywords", "SubsitesVirtualPage_Live"."CustomMetaDescription", "SubsitesVirtualPage_Live"."CustomExtraMeta", "SiteTree_Live"."ID", CASE WHEN "SiteTree_Live"."ClassName" IS NOT NULL THEN "SiteTree_Live"."ClassName" ELSE 'SiteTree' END AS "RecordClassName" FROM "SiteTree_Live" LEFT JOIN "HomePage_Live" ON "HomePage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "Library_Live" ON "Library_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "LibraryHolder_Live" ON "LibraryHolder_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "BlogEntry_Live" ON "BlogEntry_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "BlogTree_Live" ON "BlogTree_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "Calendar_Live" ON "Calendar_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "CalendarEvent_Live" ON "CalendarEvent_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "ContactPage_Live" ON "ContactPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "RegistrationForm_Live" ON "RegistrationForm_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "GridPage_Live" ON "GridPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "ErrorPage_Live" ON "ErrorPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "RedirectorPage_Live" ON "RedirectorPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "VirtualPage_Live" ON "VirtualPage_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "BlogHolder_Live" ON "BlogHolder_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "SubsitesVirtualPage_Live" ON "SubsitesVirtualPage_Live"."ID" = "SiteTree_Live"."ID" WHERE (`ParentID` = 1 AND `Summary` != 'NULL') AND ("SiteTree_Live"."SubsiteID" IN (0)) ORDER BY RAND() LIMIT 1 Column 'Summary' in where clause is ambiguous

    Regards

  • Nobrainer Web
    Avatar
    Community Member
    135 Posts

    Re: [SOLVED] Ambiguous clause Link to this post

    I think you need to specify the table for the summary filter.
    Think the error is because the Summary field also exists in another table that is joined when you do your DO::get call.

    You can try to do something like
    return DataObject::get("sitetree", "`ParentID` = ".$this->owner->ID." AND `SiteTree_Live`.`Summary` != 'NULL'", "RAND()", "", $num);

    or perhaps change the name of the Summary field.

  • jak
    Avatar
    Community Member
    46 Posts

    Re: [SOLVED] Ambiguous clause Link to this post

    You are free to create new topics for new questions, but in that case please post a link in the original thread instead of duplicating the question. I just wasted time answering the question in http://www.silverstripe.org/general-questions/show/20568 that was already answered here.

  • Harley
    Avatar
    Community Member
    153 Posts

    Re: [SOLVED] Ambiguous clause Link to this post

    Thank you both, a massive help. I can now sleep!

    Regards

    1130 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.