Jump to:

1840 Posts in 1598 Topics by 557 members

Blog Module

SilverStripe Forums » Blog Module » [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help.

Discuss the Blog Module.

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

Page: 1 2 3
Go to End
Author Topic: 2137 Views
  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    Ok didn't know that was a decorators. In decorators you have to use $this->owner to get the object they 'decorate' so in your case use - $this->owner->ID

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    [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"."Priority", "SiteTree_Live"."ChangeFreq", "SiteTree_Live"."ShowSideAd", "SiteTree_Live"."ShowBannerAd", "SiteTree_Live"."DisplayTitle", "SiteTree_Live"."ShowSidebar", "SiteTree_Live"."ParentID", "Page_Live"."Access", "Page_Live"."MenuColumns", "Page_Live"."Feature", "Page_Live"."Description", "BlogEntry_Live"."Date", "BlogEntry_Live"."Author", "BlogEntry_Live"."Tags", "BlogEntry_Live"."ImageID", "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 "Page_Live" ON "Page_Live"."ID" = "SiteTree_Live"."ID" LEFT JOIN "BlogEntry_Live" ON "BlogEntry_Live"."ID" = "SiteTree_Live"."ID" WHERE ("SiteTree_Live"."ClassName" IN ('BlogEntry')) AND (ParentID IN(584,736,50) AND ID != 736) ORDER BY Date DESC LIMIT 10 Column 'ID' in where clause is ambiguous
    GET /FA2/western-conference-semi-finals?flush=1

    Line 525 in C:\xampp\htdocs\FA2\sapphire\core\model\MySQLDatabase.php

    i got this new error, what sould i do?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    Hey Juan, this might help http://bit.ly/12Ij3BK

  • avengex
    Avatar
    Community Member
    11 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    Hi Juan,

    I'll explain your problem here and how to fix it specific to SilverStripe and SQL.

    Behind the scenes when you call DataObject::get, lots of joins happen. Because the same column name is sometimes shared between lots of tables, the SQL engine doesn't know which table's column you're referring to if there's two of them.

    Luckily, SilverStripe handles this for you easily. In this instance all you need to to do is change this:

    $posts = DataObject::get('BlogEntry','ParentID IN('.$idList.') AND ID != '. (int) $postID,'Date DESC','',$limit);

    In to this:

    $posts = DataObject::get('BlogEntry','ParentID IN('.$idList.') AND "BlogEntry".ID != '. (int) $postID,'Date DESC','',$limit);

    Notice how I've added "BlogEntry". at the front of the ID? This tells SilverStripe's ORM that you're specifically talking about BlogEntries, not any of the related tables needed to build your data model.

    While everyone's up for helping with even the simplest problem, it's safe to say that everyone would also be really grateful if you took the time to try a few things yourself: What Have You Tried?

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    hello avengex,

    it didn't work.. its still displaying on the list..

    im planing unset the array

    foreach($idArr as $key => $newvalue) {
             
    if(stripos($newvalue, $postID) !== false){

    unset($idArr[$key]);

    }
             
    }
          
    $newidList = implode(',',$idArr);

    and use this

    $posts = DataObject::get('BlogEntry','ParentID IN('.$newidList .')','Date DESC','',$limit);

    do you think its gonna work?

  • avengex
    Avatar
    Community Member
    11 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    What do you think is going wrong?

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    i think we're getting the wrong postID i also did a query in mysql there is no 736 ID in blogentry_live table. :|

    (ParentID IN(584,736,50) AND BlogEntry.ID != 736)

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: [SOLVED]Pull latest blog post except the one that is currently viewed. Please Help. Link to this post

    i am correct we're getting the wrong postID

    when i try to test this line below.. i am getting the correct results..

    $posts = DataObject::get('BlogEntry','ParentID IN('.$idList.') AND "BlogEntry"."ID" != '. (int) 2259,'Date DESC','',$limit);

    how should i correct this, $this->owner->ID so that i can get the ID of the selected post?

    2137 Views
Page: 1 2 3
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.