Hi,
I am struggling getting a relationship set up in my database. Was hoping some gurus might be able to help a brutha out. Here's the deal. I have a Client pagetype:
class Client extends Page {
.....
static $db = array(
"Sectors" => "Text",
"IsActive" => "Text",
"ExternalURL" => "Text"
);
static $has_one = array(
"ClientHolder" => "ClientHolder",
"Logo" => "Image"
);
.....
}
Then I have a NewsPage pagetype which contains a Client field:
class NewsPage extends Page {
.....
static $has_one = array(
"Client" => "Client"
);
.....
This creates a field "ClientID" in the NewsPage table, as expected. Now, in order to select the related client on a News Page in the CMS, I create a dropdown of the available Client objects in the system:
$clients = Page_Controller::GetClients();
$client_dropdownfield = new DropdownField("ClientID", "Client", $clients->toDropDownMap("Title", "Title"),null,null,"");
$fields->addFieldToTab("Root.Content.Main", $client_dropdownfield, "Content");
...And the function that gets the Clients:
class Page_Controller extends ContentController {
.....
public function GetClients() {
return DataObject::get("Client", "","Title ASC","","");
}
.....
However, when I save a NewsPage, the ClientID is always 0. It is not saving anything in this field. What am I doing wrong? I thought this would behave just like when you save a LinkedPageID from a SimpleTreeDropdownField. How do I create this relation properly?
Thanks,
Garrett