Jump to:

10842 Posts in 2512 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » ModelAdmin and Many to Many

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1521 Views
  • amacgregor
    Avatar
    Community Member
    1 Post

    ModelAdmin and Many to Many Link to this post

    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'
    );

    }

  • rbquirke
    Avatar
    Community Member
    70 Posts

    Re: ModelAdmin and Many to Many Link to this post

    what problem are you having exactly?

    1521 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.