Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Multiple has_many relationships for the same class

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1032 Views
  • Gene
    Avatar
    Community Member
    41 Posts

    Multiple has_many relationships for the same class Link to this post

    Does the DOM support the new has_many class.field syntax in 2.4? (http://open.silverstripe.org/ticket/4632)

    I have been unable to get it to work properly.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Multiple has_many relationships for the same class Link to this post

    I wasn't aware that was ready yet. That's good to see.

    I'm not sure there's anything to update, though. I think all of that is handled further upstream in the DataObject class. Can you give it a try and let me know how it goes?

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • Gene
    Avatar
    Community Member
    41 Posts

    Re: Multiple has_many relationships for the same class Link to this post

    I couldn't get it working. Here's what I have...

    static $has_many = array(
          'PackagePromos' => 'Promo.Package',
          'FlightsPromos' => 'Promo.Flights',
          'BookingPromos' => 'Promo.Booking',
       );

    function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Package', new HasManyDataObjectManager(
             $this,
             'PackagePromos',
             'Promo'
          ));
    //... other hasmanydoms

    This throws an error on save.

    I also tried replacing 'Promo' in the HasManyDom with 'Promo.Package' which seems more correct but the DOM throws an error in the constructor 'Bad Class to Singleton' - line 96. I think it needs to be split at the period at that location in order to create the class properly.

    1032 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.