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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

stupid question

Go to End

4 Posts   1193 Views


Community Member, 131 Posts

6 September 2010 at 4:04am

Edited: 06/09/2010 4:05am

I'm feeling really stupid...
I have 2 unrelated dataobjects (DO1 and DO2).
DO1 needs some data from DO2 to perform the right behaviour (everything on the model-side, so no templating).

What I have right now (in DO1) is:

function Address(){

    $a = DataObject::get('DO2', "ID=1");


        $c = $a->City;

        return $c;



I've been checking too many times for typos so I suspect there's something else I'm doing wrong.
But what...???


Community Member, 78 Posts

6 September 2010 at 5:48am

Edited: 06/09/2010 5:54am


$a = DataObject::get('DO2', "ID=1"); 

... returns a DataObjectSet

i think you should use

$a = DataObject::get_by_id('DO2', 1); 

but please provide more information regarding the DataObjects (colums, relational definitions, etc.)


Community Member, 131 Posts

6 September 2010 at 6:28am

hi rob.s,
Thanks, that did the trick.
Always thought that all kinds of dataobject::get returned a dataobjectset (the one a little bit more filled than the other ;-) ).


Community Member, 271 Posts

6 September 2010 at 7:45am

DataObject::get_one('SomeDataObject', 'ID = ' . $someID), DataObject::get_by_id('SomeDataObject', $someID) returns the same single DataObject.

DataObject::get('SomeDataObject', $wherestatement); returns a DataObjectSet even if there is one DataObject that matches the $wherestatement. This means that you can use alle methods from DataObjectSet like First, Last, MoreThenOnePage, Count etc. in your php code or your template file (just the notation is little different).

Hope this explains it a little bit more.