RedBeanPHP 4
The Power ORM

Meta data

Beans contain meta data. For instance, the type of the bean is stored in the meta data. To obtain the type of a bean:


You can also store your own meta data in a bean:

    $bean->setMeta'''secret' );

this data will not get stored in the database.


Some meta data is accessible using convenience method. For instance, if you would like to know whether a bean has been changed since it got retrieved from the database use the tainted() method.




Note that a bean is marked as tainted if a list gets accessed. You can also set the tainted flag yourself.


To determine if a certain property has changed:

    $book R::load'book'$id );
$book->hasChanged'title' ); //returns FALSE
$book->title 'New title';
$book->hasChanged'title' ); //returns TRUE

To get the old value of the property:

    $book->old'title' );

The behaviour of hasChanged sometimes suprises people, for instance take a look at the following code:

    $employee R::load'employee'$id );
var_dump$employee->hasChanged'organisation' ) ); //FALSE
var_dump$employee->hasChanged'organisation_id' ) ); //FALSE
$employee->organisation $newOrganisation;
var_dump$employee->hasChanged'organisation' ) ); //TRUE
var_dump$employee->hasChanged'organisation_id' ) ); //FALSE

The reason for this behaviour is that organisation_id will not be updated automatically until you call R::store(). Until, then the property has not been changed.

Testing Equality

To test whether two beans have the same type and primary key ID:

    $bean->equals$otherBean );


To determine if a bean is empty, or only contains empty values (everything that qualifies as empty() in PHP) use:


Copy meta data

You can copy meta data from another bean like this:

    $bean->copyMetaFrom$otherBean );


RedBeanPHP Easy ORM for PHP © 2014 () and the RedBeanPHP community () - Licensed New BSD/GPLv2 - RedBeanPHP Archives