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.

Data Model Questions

stupid question


Reply

4 Posts   842 Views

Avatar
theAlien

6 September 2010 at 4:04am (Last edited: 6 September 2010 4:05am), Community Member, 131 Posts

Hi,
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");

if($a){

$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...???

Avatar
rob.s

6 September 2010 at 5:48am (Last edited: 6 September 2010 5:54am), Community Member, 78 Posts

HI,

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

Avatar
theAlien

6 September 2010 at 6:28am Community Member, 131 Posts

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

Avatar
Martijn

6 September 2010 at 7:45am Community Member, 271 Posts

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.