Orm
Orm is short for Object
Relational Mapper which does 2 things: it maps your database table rows to objects and it allows you
to esteblish relations between those objects.
It follows closely the
Active Record Pattern, but was also influenced by other systems.
Relations: Belongs To
Has the primary key of the relation keps in its table, belongs to 1 related object. This is the other side of a HasOne or HasMany relation.
Example
Let's say we have a model Model_Comment and it belongs to a Model_Post (which in turn has many comments) the ID of the Model_Post is saved with the Model_Comment instance in its own table. This means the comments table will have a column post_id (or something else you configure). If you keep to the defaults all you need to do is add 'post' to the $_belongs_to static property of the Model_Comment:
protected static $_belongs_to = array('post'));
Full config example with defaults as values
// in a Model_Comment which belong to a post
protected static $_belongs_to = array(
'post' => array(
'key_from' => 'comment_id',
'model_to' => 'Model_Post',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
)
);