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

selecting data AS...


Reply

3 Posts   1354 Views

Avatar
jester12345

12 May 2009 at 9:57am Community Member, 8 Posts

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

20 May 2009 at 8:26am Community Member, 8 Posts

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
simon_w

20 May 2009 at 8:46am Forum Moderator, 474 Posts

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.