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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

[SOLVED] Automatic scaffolding not returning the correct number of children

Go to End

3 Posts   791 Views

Xananax Prozaxx

Community Member, 11 Posts

21 October 2011 at 2:50am

Edited: 21/10/2011 2:52am

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.


Forum Moderator, 1391 Posts

21 October 2011 at 6:50am

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

Community Member, 11 Posts

21 October 2011 at 12:44pm

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.