Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin and Many to Many


Go to End


2 Posts   2404 Views

Avatar
amacgregor

Community Member, 1 Post

15 February 2009 at 8:03am

Edited: 16/02/2009 7:31am

Hi,

I have been working with the ModelAdmin for a few days now and it works beatifully with the exception of many to many relationships; so any help fixing or working around this will be awesome

Model Admin class

class PortfolioAdmin extends ModelAdmin {
   
  protected static $managed_models = array(
      'Project',
      'Category',
      'Client',
      'Technology'
   );
 
  static $url_segment = 'projects'; // will be linked as /admin/products
  static $menu_title = 'Portfolio Admin';
 
} 

Project class

 class Project extends DataObject {
 
   static $db = array(
      'Name' => 'Varchar',
      'ProjectCode' => 'Varchar',
      'Description' => 'Text',
      'Budget' => 'Currency'
   );
 
   static $many_many = array(
      'Category' => 'Category',
      'Technology' => 'Technology'
   );
 
   static $has_one = array(
      'Client' => 'Client'
   );
   
   static $searchable_fields = array(
      'Name',
      'ProjectCode' 
   );
 
} 

Category class

 class Category extends DataObject {
   static $db = array(
      'Title' => 'Text',
      'Description' => 'Text'
   );
   static $belongs_many_many = array(
      'Project' => 'Project'
   );
} 

Technology Class
 class Technology extends DataObject {
   static $db = array(
   		'TechName' => 'Varchar',
		'TechVersion' => 'Varchar',
		'Description' => 'Text'
   );
    static $belongs_many_many = array(
      'Project' => 'Project'
   );
} 

Client class

 class Client extends DataObject{

	static $db = array(
		'Title' => 'Varchar',
		'Company' => 'Varchar',
		'ContactName' => 'Varchar',
		'Webpage' => 'Varchar',
		'Email' => 'Varchar'
	);
	static $has_one = array(
	);
	static $field_names = array(
		'Title' => 'Title'
	);
    static $searchable_fields = array(
      'Title',
      'Email' 
    );

} 

Avatar
rbquirke

Community Member, 70 Posts

16 February 2009 at 2:08pm

what problem are you having exactly?