Hi everyone,
I am trying to filter some DataObjects based on the Title field of a field in that DataObject. However the returned array is empty.
My Product.php :
class Product extends DataObject {
private static $db = array (
'Name' => 'Varchar'
);
private static $has_one = array (
'Supplier' => 'SupplierPage'
);
private static $many_many = array (
'Categories' => 'CategoryPage',
);
}
My SupplierPage.php :
class SupplierPage extends Page {
private static $db = array (
'ShortDescription' => 'Text',
);
private static $has_many = array (
'Products' => 'Product'
);
}
My CategoryPage.php :
class CategoryPage extends Page {
private static $db = array (
'ShortDescription' => 'Text',
);
private static $belongs_many_many = array (
'Products' => 'Product'
);
}
class CategoryPage_Controller extends Page_Controller {
public function GetSuppliers() {
return SupplierPage::get();
}
public function GetProductsBySupplier($supplier) {
return $this->Products(Null, 'Name ASC')->filter('Supplier.Title', $supplier);
}
}
My template CategoryPage.ss
<!-- Sorting by Suppliers-->
<% loop GetSuppliers() %>
<!-- listing products for supplier $Title -->
<% loop $Up.GetProductsBySupplier($Title) %>
<!-- found product $Name from $Supplier.Title -->
<% end_loop %>
<% end_loop %>
The issue is that I never find any product. Could you please enlighten me? I looked in the API, but I could not understand what was the function call for the
$this->Products()
. Also, I found some infos on DataObjectSet which seem to be deprecated.What is the current way of doing that?
Thank you in advance!