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

Fetching (has_one) related Date


Reply

3 Posts   1202 Views

Avatar
rob.s

29 May 2009 at 3:38am Community Member, 78 Posts

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 %>

Avatar
rob.s

29 May 2009 at 3:41am Community Member, 78 Posts

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

Avatar
rob.s

29 May 2009 at 4:23am Community Member, 78 Posts

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