3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2332 Views |
-
ModelAdmin - add an existing DataObject in a Many_Many

10 July 2009 at 9:58pm Last edited: 11 July 2009 12:31am
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
Country.phpclass ContactsManager extends ModelAdmin {
public static $managed_models = array(Business','Country');
static $url_segment = 'contact-us';
static $menu_title = 'Contact Us';
}Business.phpclass Country extends DataObject {
static $db = array('Name' => 'Varchar');
static $belongs_many_many = array ('Businesses' => 'Business');
}class 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)

-
Re: ModelAdmin - add an existing DataObject in a Many_Many

24 November 2009 at 7:28am
Hi,
does there already exist a solution for this kind of problem? I would need it urgently....
Greetings!
-
Re: ModelAdmin - add an existing DataObject in a Many_Many

23 December 2009 at 10:55am
I had exactly the same issue with many_many relationships in ModelAdmin. Seems that there is a bug basically in ModelAdmin. In case you didn't notice, Ali's edit (at the top of the first post) is a fix that works great.
| 2332 Views | ||
|
Page:
1
|
Go to Top |


