7912 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | ||
| Author | Topic: | 2486 Views |
-
Re: Joining two tables created using DataObject

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:
Aram
www.ssbits.com - Your one stop SilverStripe learning resource.
-
Re: Joining two tables created using DataObject

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).
-
Re: Joining two tables created using DataObject

4 November 2011 at 10:08am Last edited: 4 November 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
-
Re: Joining two tables created using DataObject

4 November 2011 at 10:30am
Great, I'll play around with that. Thanks.
-
Re: Joining two tables created using DataObject

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.
| 2486 Views | ||
| Go to Top |


