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)