3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 485 Views |
-
Page Relations: $has_one Using Dropdown Map - Not Saving to Field

1 March 2012 at 5:52am
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 -
Re: Page Relations: $has_one Using Dropdown Map - Not Saving to Field

4 March 2012 at 6:18am
Hi Garret,
try to change the field name from ClientID to Client:
$client_dropdownfield = new DropdownField("Client", "Client", $clients->toDropDownMap("Title", "Title"),null,null,"");
because the named relation is "Client"
Works?
Rob
| 485 Views | ||
|
Page:
1
|
Go to Top |


