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

selecting data AS...

Go to End

3 Posts   1764 Views


Community Member, 8 Posts

12 May 2009 at 9:57am

I know you can do this with the SQLQuery object, but that makes it harder to get live/dev data appropriately.

I am trying to query data out using something like:
$posts = DataObject::get('Page', "`ClassName` IN ('EventEntry', 'NewsPage')");

But, the Date field is not named Date in one of these. So, I need to get "EventStartDate AS Date" worked in there somewhere.

My current solution is to query each of these out separately and use PHP to munge them together. Is there a built-in SilverStrip way to do this?


Community Member, 8 Posts

20 May 2009 at 8:26am

My solution for this was to change the database structure such that both objects had an EventStartDate. This worked because the site wasn't live yet and we were free to make changes. This would not work (at least not easily) in the case where the site was live and you had existing data.

So, I'm still looking for a reasonable solution to this problem. Surely I'm not the first person to have this problem.


Community Member, 473 Posts

20 May 2009 at 8:46am

You could have a getDate() (or just Date()) method that returns $this->EventStartDate or $this->dbObject('EventStartDate') depending on if you want the class associated with the field or just the field value.