Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Fetching (has_one) related Date

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

Page: 1
Go to End
Author Topic: 1149 Views
  • rob.s
    Avatar
    Community Member
    78 Posts

    Fetching (has_one) related Date Link to this post

    Hi,

    i'm new to SS but i like it.

    In my first training-Project I handle 2 Models within Admin an new Page Type.
    Event, Location
    (Event has_one Location)
    Works Perfectly.

    In detail-view i would like to fetch the details of the Event including the details of the Location

    Controller:

    function details()
    {
    $event_id = (int)Director::urlParam('ID');
    $event = DataObject::get_by_id('Event', $event_id);
    /.......
    }
    [/code}

    View:

          <% if Eventdetails %>
          <dl>
             <% control Eventdetails %>
              <!-- Data from Model "Event" -->
                <dt>Datum:</dt><dd>$Date.Format(d.m.Y)</dd>      
                <dt>Start:</dt><dd>$Start</dd>      
                <dt>Ende:</dt><dd>$End</dd>   
                <!-- Additional Info from Model "Location" should go here -->   
                <dt>Street:</dt><dd>$Street</dd>       
                <dt>Zip:</dt><dd>$Zip</dd>       
                <dt>Phone:</dt><dd>$Phone</dd>       
             <% end_control %>          
          </dl>
          <% end_if %>

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: Fetching (has_one) related Date Link to this post

    Sorry, incomplete

    Heres the Controller-Action:

    function details()
    {
    $event_id = (int)Director::urlParam('ID');
    $details = DataObject::get_by_id('Event', $event_id);
    return $this
    ->customise(array('Eventdetails' => $details))
    ->renderWith(array('Tourdates_details', 'Page'));
    }

    How do i fetch/join/merge the Data from both models ?

    Any ideas would be great!

    Robert

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: Fetching (has_one) related Date Link to this post

    got it working:

    function details()
    {
    $event_id = (int)Director::urlParam('ID');
    $details = DataObject::get_by_id('Event', $event_id);
    $location = $details->Eventlocation();
    return $this
    ->customise(array('Eventdetails' => $details, 'Eventlocation'=>$location))
    ->renderWith(array('Tourdates_details', 'Page'));
    }

    works.....

    1149 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.