Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » $many_many DataObjects no longer displayed

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2097 Views
  • oleze
    Avatar
    Community Member
    64 Posts

    $many_many DataObjects no longer displayed Link to this post

    I have a class

    <?php
    class Brochure extends File{

       static $db = array (
          'Title' => 'Text',
          'Name_de' => 'Text',
          'Name_en' => 'Text',
          "ShowInSearch" => "Boolean"
       );

       static $belongs_many_many = array(
          'Pages' => 'Page'
       );
       
       static $singular_name = 'Brochure';
       static $plural_name = 'Brochures';
       
       static $defaults = array (
             'ShowInSearch' => 0
       );
       
       public function getCMSFields_forPopup()
       {   
          $filefield = new FileUploadField('Parent','PDF');
          $filefield->removeFolderSelection();
          $filefield->uploadFolder = 'brochures/';
          return new FieldSet(
             new TextField('Name_de'),
             new TextField('Name_en'),
             $filefield
          );
       }
       
       
       

       
    }   
    ?>

    and a PageType that has a many_many relation to the brochures

    class ReferencePage extends Page {
    ....

    static $many_many = array (

          'Brochures' => 'Brochure',
       );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    ...

    // Adding Brochures      
              $brochurefilemanager = new ManyManyFileDataObjectManager(
                $this, // Controller
                'Brochures', // Source name
                'Brochure', // Source class
                'Parent', // File name on DataObject
                array(
                   'Name' => 'Name'
                   ), // Headings
                'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
                // Filter clause
                // Sort clause
                // Join clause
                );
                $brochurefilemanager->default_view = 'list';
                $brochurefilemanager->setAllowedFileTypes(array('pdf'));
                $brochurefilemanager->allowUploadFolderSelection = false;
                $brochurefilemanager->setUploadFolder('assets/brochures/');
                
             $fields->addFieldToTab("Root.Content.AttachedFiles",$brochurefilemanager);

    ....

    }

    But these DataObjects are no longer displayed within the backend or the frontend. I looked for them in my database. Tables are there and okay. Does anyone see the problem? Thank you for your help. SS-Version is 2.4.5 with latest version of the DataObject_Manager Module.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    Hi Oleze,

    I think your many_many relationship should be:

    static $belongs_many_many = array(
    'Pages' => 'ReferencePage'
    );

    Aram

    www.SSBits.com - Your one stop SilverStripe learning resource.

  • oleze
    Avatar
    Community Member
    64 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    Thank you Aram,
    the problem is:

    Those Brochures also belong to VehiclePages and others. Do you think that's the problem? Do I need e many_many relation for every Page type a Brochure belongs to?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    Hi Oleze,

    You either need to add the many_many static to Page.php along with the DOM, or you need to add a number of belongs_many_many in the DataObject, otherwise SS is gonna get confused because you are telling it it belongs to a relationship on the Page class, but there is no relationship defined on that Class.

    Aram

    www.SSBits.com - Your one stop SilverStripe learning resource.

  • oleze
    Avatar
    Community Member
    64 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    Okay, I changed my code to:

    static $belongs_many_many = array(
    'ReferencePages' => 'ReferencePage',
    'VehiclePages' => 'VehiclePage'
    );

    I still can't see the DataObjects (Brochures) on my ManyManyFileDataObjectManager in the backend. The tables and ID's match each other for all relations in my database....

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    What happens if you create a new one? Does it show in the DOM?

    What is the db table called?

    Aram

  • oleze
    Avatar
    Community Member
    64 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    Nope, doesn't show up. Tables are called "ReferencePage_Brochures" and "VehiclePage_Brochures". Brochures are saved in the "Brochure" table which joins "File". Everything as it should be, I think.....

  • UncleCheese
    Avatar
    4085 Posts

    Re: $many_many DataObjects no longer displayed Link to this post

    ManyManyFileDOM doesn't manage File or File subclasses. It manages DataObject subclasses that have a file relation within them.

    2097 Views
Page: 1 2
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.