Table of Contents

Belongs to

The information below is copied from the API documentation on belongs_to associations
http://api.akelos.org/ActiveRecord/Associations/AkBelongsTo.html

Belongs to adds the following methods for retrieval and query for a single associated object that this object holds an id to.

Example

A Post class declares belongsTo('author'), which will add:

$Post->author->load(); (similar to $Author->find($author_id);)
$Post->author->assign($Author); (similar to $Post->author_id = $Author->getId();)
$Post->author->build($Author); (similar to $Post->author = new Author();)
$Post->author->create($Author); (similar to $Post->author = new Author(); $Post->author->save();)

The declaration can also include an options hash to specialize the behavior of the association.

Options

Option examples

var $belongs_to = array('firm', array('primary_key_name' => 'client_of'));
 
var $belongs_to = array('author', array('class_name' => 'Person',
                                        'primary_key_name' => 'author_id'));
 
var $belongs_to = array('valid_coupon', array('class_name' => 'Coupon',
                                              'primary_key_name' => 'coupon_id',
                                              'conditions' => "'discounts' > 'payments_count'"));