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 /

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

Fetching (has_one) related Date


Go to End
Reply


3 Posts   1333 Views

Avatar
rob.s

Community Member, 78 Posts

29 May 2009 at 3:38am

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

Community Member, 78 Posts

29 May 2009 at 3:41am

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

Community Member, 78 Posts

29 May 2009 at 4:23am

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