Has One

Let's says that we have a Contact that only can have one country assigned.

In model/contact.php

class Contact extends ActiveRecord
{
	var $belongs_to = array('country'=>array('foreign_key'=>'country_id'));		 
}

In model/country.php

class Country extends ActiveRecord
{
	var $has_many = 'contacts';	 
}

Then in the controller/contact.php

    function show()
    {  		
 	$this->Contact->country->load(); 
    }

Now in contact.show.tpl we just show the country

          {contact.country.name}
 
has_one.txt · Last modified: 2008/09/19 17:46 by 70.75.42.247
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki