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

GROUP BY in DataObject::get


Reply


3 Posts   2950 Views

Avatar
sca123

Community Member, 61 Posts

14 September 2010 at 4:46am

Hi
Where do I put a GROUP BY statement into the DataObject:get?

I currently have:

return DataObject::get("Specification","Director::currentPage()->ID."=PageID","OutputPower)","","");

Thanks in advance.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

14 September 2010 at 5:03am

That's not really what DataObject::get() is designed to do. Just use a SQLQuery() object.

$sql = singleton('SomeObject')->getExtendedSQL();
$sql->select[] = "SUM(SomeField) AS Total";
$result = $sql->where("Foo = 'Bar'")
->innerJoin("JoinTable", "`JoinTable`.ID = `AnotherTable`.ID")
->groupby("1")
->having("Foo > 3")
->execute();

Avatar
Graphicator

Community Member, 62 Posts

17 September 2011 at 1:19pm

I may have followed upon the original question here [url]http://bit.ly/n5y3du[/url]