addRelationship($relName,$relType,$foreignClass, $thisKey, $relKey = null, $outKey = null, $relOutKey = null, $relTable = null, $lazy = false)

This method creates a relationship field into the mapping.
Relationship fields has different behavior than the column fields they comunicate with another PhpBURN models connecting them by some
kind of reference.

@param String $relName
@param int $relType
@param String $foreignClass
@param String $thisKey
@param String $relKey
@param String $outKey
@param String $relOutKey
@param String $relTable
@param Boolean $lazy
@return PhpBURN_Map


This is how you will call your relationship such as “albums, pictures, comments, rate, tags, etc”

It ALWAYS refers to self:: static constants:

Name of the class you will reference to. It should be ALWAYS a mapped PhpBURN Model in any package.

Any reference should be at least between two fields, thisKey as it say reference to the field alias on the current Model that will reference with the field alias in the external Class/Model.

It has two different usages.
Using with self::ONE_TO_ONE or self::ONE_TO_MANY:
In this case it will reference to the external class field alias

Using with self::MANY_TO_MANY:
In this case it will be the $relTable column that references with $thisKey.

Used only in self::MANY_TO_MANY cases. This represents the external class field wich will be used to compare with $relTable column.

Used only in self::MANY_TO_MANY cases. This represents the $relTable column that references to $outKey

Used only in self::MANY_TO_MANY cases. This is the reference table that connects one model to another, that don’t need to be mapped as a PhpBURN Model, it must only exists in the database with the apropriated database relationships.


Relationships used to be a painful thing to developers to handle with, but now it became a very simple thing, all you need is create the tables, map the model and say that is a relationship and start using transparently.

Here we will see a detailed explanation of how does Relationships works and how to set them.

Lets assume the following database structure:

EER Diagram

EER Diagram

In simple words:

Users has many Albums ( self::ONE_TO_MANY )
Albums has many Pictures ( self::ONE_TO_MANY )
many Albums has many Tags ( self::MANY_TO_MANY )
many Pictures has many Tags ( self::MANY_TO_MANY )

So in this case we have 6 ( six ) Tables and 3 ( three ) Models. I will not be so deep explain relationships because you can find it at Tutorial area in

So how will our code be into our models?

Well, first of all you can create relationships on-the-fly but we recommend you to create it at _mapping() magic method at PhpBURN Model.

According to the figure above:


public function _mapping() {





public function _mapping() {





public function _mapping() {




WOW!!!!!!! That’s it? YEAH!!! That is it… pretty easy uh? That’s all you need to put this complex relationship structure working for you without any more troubles.

Relationships can be fun, BE CREATIVE.