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.

Customising the CMS /

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

Member has many link, and viewing records


Go to End


4 Posts   1841 Views

Avatar
Parker1090

Community Member, 46 Posts

28 March 2013 at 11:50pm

Edited: 29/03/2013 12:03am

Hello!
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:
BasicMembers.php

<?php
class BasicMembers extends DataExtension {
	...
	static $has_one = array(
		'Organisation' => 'Organisation'
	);
	
}
?>

And in Organisation.php
<?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

[Edit]
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)

Avatar
PhiloPachem

Community Member, 4 Posts

20 May 2013 at 6:07pm

Edited: 20/05/2013 6:11pm

Hi!
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')
ORDER BY DESC
LIMIT 15

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

this is auto i didn't made nothing

i have

problema.php
<?php
class Problema extends DataObject {
static $db = array(
'Desc' => 'Varchar',
'FEN' => 'Varchar(90)',
'Lances' => 'Text',
);
static $has_one = array(
'TipoProblema' => 'TipoProblema'
);
}

and

TipoProblema.php

<?php
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
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'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
$config
);
// 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);

$problemas->setPageLength(1);

return $problemas;
}

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

function init() {

parent::init();
Requirements::css("mysite/javascript/pgnviewer/ltpgnviewer.css");

}
}

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?

Avatar
PhiloPachem

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

Avatar
openbees

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 http://www.silverstripe.org/general-questions/show/20477 :)

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