edit: I figured this out. For those interested, I installed DataObjectManager, renamed the folder to 'dataobject_manager', and added this code to the Business.php file
function getCMSFields() {
$f = parent::getCMSFields();
$manager = new ManyManyDataObjectManager(
$this, // Controller
'Countries', // Source name
'Country', // Source class
array('Region'=>'Region','Name' => 'Name'),
'getCMSFields_forPopup' );
$f->removeFieldFromTab('Root', 'Countries'); // replace the tab with MMDOM tab
$f->addFieldToTab('Root.Country', $manager);
return $f; }
Kinda new to this whole modeladmin thing, so excuse the probably daft question, but it seems fairly obvious that in a many_many relationship I'd want to be able to add an existing DataObject to my relationship, and I'm wondering how to implement this. Here's my current implementation (removed pointless stuff):
ContactsManager.php
class ContactsManager extends ModelAdmin {
public static $managed_models = array(Business','Country');
static $url_segment = 'contact-us';
static $menu_title = 'Contact Us';
}
Country.phpclass Country extends DataObject {
static $db = array('Name' => 'Varchar');
static $belongs_many_many = array ('Businesses' => 'Business');
}
Business.phpclass Business extends DataObject {
static $db = array('Title' => 'Varchar');
static $has_one = array('Logo' => 'Image');
static $many_many = array('Countries'=>'Country');
}
Below is what I get when I edit a country (when I want to add an existing business)