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:

Customising the CMS /

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

Member has many link, and viewing records

Go to End

4 Posts   1327 Views


Community Member, 46 Posts

28 March 2013 at 11:50pm

Edited: 29/03/2013 12:03am

I've created a new table through SilverStripe for organisations (an organisation can have many members, a member can only have one organisation).

I have the following code:

class BasicMembers extends DataExtension {
	static $has_one = array(
		'Organisation' => 'Organisation'

And in Organisation.php
class Organisation extends DataObject {
	static $has_many = array(
		'Employee' => 'Member',

And additionally...
class OrganisationManagement extends ModelAdmin {
	public static $managed_models = array('Organisation','Member')
	static $url_segment = 'organisations';
	static $menu_title = 'Organisation Management';

It works fine - a member can belong to an organisation, and an organisation can have members. However, you can only link one way. Using the ModelAdmin, if you view employees of an organisation, you get the list and can add a brand new member, but you can't search (returns an error of "An error occured while fetching the data from the server. Please try again later". A little box with an error appears, but mostly cut off and disappears, so I'm yet to actually copy it, will edit with the error shortly).

Also, when a new organisation is created it will say, e.g.: 'Saved Organisation "#1"' - How can this be changed to the organisations name rather than #1, #2 etc.?

Sorry if this post is a bit long, but I wanted to give you the full picture. It's the first time I've tried doing this, and although mostly successful, this error seems to be a barrier for me.

Many Thanks

The error in the little box:
Error at line 190 of /framework/forms/gridfield/GridFieldAddExistingAutocompleter.php

The error in the error log:
[28-Mar-2013 10:57:28] Error at framework/forms/gridfield/GridFieldAddExistingAutocompleter.php line 190: Uncaught LogicException: GridFieldAddExistingAutocompleter: No searchable fields could be found for class "Member" /admin/organisations/Organisation/EditForm/field/Organisation/item/1/ItemEditForm/field/Employee/search?gridfield_relationsearch=s)


Community Member, 4 Posts

20 May 2013 at 6:07pm

Edited: 20/05/2013 6:11pm

I have same issue with 3.05
but when i go to the log i get

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESC LIMIT 15' at line 1 (http://localhost/gx_113/index.php/admin/pages/edit/EditForm/field/Problemas)
[20-May-2013 07:04:56] Error at framework/model/MySQLDatabase.php line 580: Couldn't run query:
SELECT DISTINCT "Problema"."ClassName", "Problema"."Created", "Problema"."LastEdited", "Problema"."Desc", "Problema"."FEN", "Problema"."Lances", "Problema"."TipoProblemaID", "Problema"."ID", CASE WHEN "Problema"."ClassName" IS NOT NULL THEN "Problema"."ClassName" ELSE 'Problema' END AS "RecordClassName", ""
FROM "Problema"
WHERE ("TipoProblemaID" = '22')

this query don't run i tested it in phpmyadmn :(

this is auto i didn't made nothing

i have

class Problema extends DataObject {
static $db = array(
'Desc' => 'Varchar',
'FEN' => 'Varchar(90)',
'Lances' => 'Text',
static $has_one = array(
'TipoProblema' => 'TipoProblema'



class TipoProblema extends Page {

static $has_many = array(
'Problemas' => 'Problema'

public function getCMSFields() {
// Get the fields from the parent implementation
$fields = parent::getCMSFields();
// Create a default configuration for the new GridField, allowing record editing
$config = GridFieldConfig_RelationEditor::create();
// Set the names and data for our gridfield columns
'Desc' => 'Desc',
'FEN' => 'FEN',
'Lances' => 'Lances'


// 'TipoProblema'=> 'TipoProblema'
// ,'TipoProjecto'=> 'TipoProjecto' // Don't use is this an issue?! Retrieve from a has-one relationship

// Create a gridfield to hold the student relationship
$studentsField = new GridField(
'Problemas', // Field name
'Problemas', // Field title
$this->Problemas(), // List of all Problemas
// Create a tab named "Students" and add our field to it
$fields->addFieldToTab('Root.Problemas', $studentsField);
return $fields;


class TipoProblema_Controller extends Page_Controller {

public function MostraProblema() {

$problemas = new PaginatedList(Problema::get($callerClass = "Problema",$filter = "`TipoProblemaID` = '".$this->ID."'"), $this->request);


return $problemas;

public function aleatorio() {
$totalproblemas = Problema::get($callerClass = "Problema",$filter = "`TipoProblemaID` = '".$this->ID."'");
return HTTP::setGetVar('start', rand(0,$totalproblemas->Count()));

function init() {



The CMS shows every records of problema and let me edit it, it just don't search
Sometimes when i force the search i get this in my log

[20-May-2013 07:09:05] Error at framework/forms/gridfield/GridFieldAddExistingAutocompleter.php line 190: Uncaught LogicException: GridFieldAddExistingAutocompleter: No searchable fields could be found for class "Problema" (http://localhost/gx_113/index.php/admin/pages/edit/EditForm/field/Problemas/search?gridfield_relationsearch=%23)

How can i give a field to search?! anyone can help?


Community Member, 4 Posts

24 May 2013 at 12:03am

Edited: 24/05/2013 12:25am

I replaced the field Desc for Title

Know i can search on CMS/Admin

But why can't i used the fields i want ?!?! :)

I can but with a Title will make things easier, so i learn :)

So ID is auto, Title you put and then you can add the records you want.

This was a simple solution, thanks openbees

If you want to know the mysql commands here they are

Updating the fields...

UPDATE Problema SET `Title` = `Desc`

Droping the column...

ALTER TABLE Problema DROP COLUMN Problema.Desc


Community Member, 3 Posts

24 May 2013 at 12:15am

In case if someone want to dig deeper on this topic he/she can follow this thread :)

P.S. Not a right place to post this question .