Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Joining two tables created using DataObject

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: 3172 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Joining two tables created using DataObject Link to this post

    Hi Guy,

    Not entirely sure what you mean but take a look at this, it's the same principle:

    http://www.ssbits.com/snippets/2009/adding-a-thumbnail-to-a-dataobjectmanager-or-complex-table-field/

    Aram

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

  • ROlckers
    Avatar
    Community Member
    8 Posts

    Re: Joining two tables created using DataObject Link to this post

    @guywatson - did u manage to find a solution to this?

    I'm having the same issue. I saw that the constructed query only select fields from the first table in the DataObjectManager even if you JOIN another table. If I can find a way to add the required field to the select query, it would solve my problem (I hope). It also ads a GROUP BY clause, which would make it challenging to add another field in the query.

    Any help guys? I started a topic on this exact issue which I assume is related here (http://www.silverstripe.org/dataobjectmanager-module-forum/show/18446).

  • guywatson
    Avatar
    Community Member
    16 Posts

    Re: Joining two tables created using DataObject Link to this post

    Hi ROlckers

    This seems to be a problem with dom, because it works fine with complex table fields. I still needed to use a dom however so the way i got around it was to create a get function on the CustomModel dataobject i.e. something like this

    public function getCustomParentPageTitle() {
       return $this->CustomParentPage()->Title;
    }

    Then in the XYZ Page

    public function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.CustomWidgets", new DataObjectManager(
          $this,
          'CustomModels',
          'CustomModel',
          array( 'CustomName' =>'Custom Model Name',
             'CustomParentPageID' =>'Custom Parent Page ID'
             'CustomParentPageTitle' =>'Custom Parent Title' ),
          '   getCMSFields_forPopup'
       ));
       return $fields;
    }

    Note you omit the get and CustomParentPageTitle is the function call on the dataobject

    Also you should just be able to go CustomParentPageID.Title, but this doesn't work for me (well on a many_many relationship) i haven't tried a has_many relationship

    Guy

  • ROlckers
    Avatar
    Community Member
    8 Posts

    Re: Joining two tables created using DataObject Link to this post

    Great, I'll play around with that. Thanks.

  • ROlckers
    Avatar
    Community Member
    8 Posts

    Re: Joining two tables created using DataObject Link to this post

    Legend! I took the $has_one column id, and used that inside the function, there I could use any calculation to get the Title from SiteTree or from another model.

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