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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Query has_many from sibling page

Go to End



Community Member, 1 Post

20 August 2014 at 4:18am

Hi, I am new to the Silverstripe way so this might be totally off the wall but...

I am trying to select and filter pages (SOURCE) based on a has_many property they have from a sibling page (QUERY) e.g.

class HelpAnswer extends Page {
private static $db = array();

private static $has_many = array(
'Taxonomy' => 'CategoryTag'
class CategoryTag extends DataObject {
static $db = array(
'Category' => 'Varchar(50)',
'Tag' => 'Varchar(15)'

public static $has_one = array(
'HelpAnswer' => 'HelpAnswer'

class HelpTopic extends Page {
static $db = array(
'Category' => 'Varchar(50)'
class HelpTopic_Controller extends Page_Controller {
public function getAnswers($tag) {

I have tried things like the following but I haven't yet been able to get enough access across the dataObjects to pull the query together. Ultimately I am looking for the syntax magic I can sprinkle in at XXXXXXX in order to select all the Help_Answer pages that have the specified 'Category'. Further to this I would also like to group them by 'Tag'.

$answers = $parent->Children(); // Works, but no filtering
$answers = $parent->Children()->filter('ClassName','HelpAnswer'); // Works, but not enough filtering
$answers = $parent->Children()->filter('Category', $this->Category); // Returns Records, not to requirement
$answers = $parent->Children()->filter('Taxonomy.Category', $this->Category); // Error
$answers = $parent->Children()->filter('ClassName','HelpAnswer')->filter('Taxonomy.Category', $this->Category); // Error