Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Automatic scaffolding not returning the correct number of children

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

Page: 1
Go to End
Author Topic: 388 Views
  • Xananax Prozaxx
    Avatar
    Community Member
    11 Posts

    [SOLVED] Automatic scaffolding not returning the correct number of children Link to this post

    Ok So I have these two models:

    class NewsPage extends Page {
    static $has_many = array ('News' => 'News');
    }
    class News extends DataObject{
    static $has_one = array('Parent'=>'NewsPage');
    }

    (I am omitting details, but there is nothing out of the ordinary, simply $db, $summary_fields, and getCMSFields()).

    In my template, if I <% control News %>, I get 4 news. But there are 10.
    If I add this function in my NewsPage:

       function News(){
          return DataObject::get('News','ParentID="'.$this->ID.'"');
       }

    It works. This has me quite baffled; isn't the automatic $NewsPage->News function supposed to be doing just that?
    Note that if I call the function getNews() I get only 4 news again.

    Also, I checked in the database and all News objects have a correct ParentID set.

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: [SOLVED] Automatic scaffolding not returning the correct number of children Link to this post

    If you set the site in dev mode, and then do a ?showqueries=1 you can at least take a look at the query and see wat it's doing...

  • Xananax Prozaxx
    Avatar
    Community Member
    11 Posts

    Re: [SOLVED] Automatic scaffolding not returning the correct number of children Link to this post

    Ok got it...Very stupid of me.
    There is this customized Page class that I recycle across sites, and it has a News($number=4) function, usually for displaying stuff in sidebars.

    388 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.