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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

selecting data AS...


Go to End


3 Posts   2177 Views

Avatar
jester12345

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?

Avatar
jester12345

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.

Avatar
(deleted)

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.