Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » selecting data AS...

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

Page: 1
Go to End
Author Topic: 1336 Views
  • jester12345
    Avatar
    Community Member
    8 Posts

    selecting data AS... Link to this post

    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?

  • jester12345
    Avatar
    Community Member
    8 Posts

    Re: selecting data AS... Link to this post

    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.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: selecting data AS... Link to this post

    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.

    1336 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.