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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Joining two tables created using DataObject


Go to End
Reply


13 Posts   3340 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

3 May 2011 at 11:26pm

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.

Avatar
ROlckers

Community Member, 8 Posts

4 November 2011 at 9:48am

@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).

Avatar
guywatson

Community Member, 16 Posts

4 November 2011 at 10:08am

Edited: 04/11/2011 10:29am

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

Avatar
ROlckers

Community Member, 8 Posts

4 November 2011 at 10:30am

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

Avatar
ROlckers

Community Member, 8 Posts

4 November 2011 at 11:14am

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.

Go to Top