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

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


Go to End


3 Posts   1305 Views

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

Avatar
martimiz

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

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