Custom getters

Besides, properties, nested beans and nested lists a bean may also contain custom getters. If you want to map a relation which is not supported by RedBeanPHP you can use this technique.

For instance, consider the retrieval of historical data. We have a $person bean and our task is to get all the related $events sorted by date. What RedBeanPHP can do is retrieve all events like this

 
    $person
->ownEvents 

But that might not be the correct order! In this case we better write our own getter:


    
class Model_Person extends RedBean_SimpleModel {
        public function 
getEvents() {
            return 
R::find('event',
            
' person_id = ? order by `date` asc',array(
            
$this->id));
        }
    }

To use this custom getter:


    $person 
R::load('person',$certainID);
    
$eventBeans $person->getEvents();

Notice that RedBeanPHP knows that Model_Person belongs to bean $person. This is called FUSE because the bean and the model are fused. Read more about models and fuse.

BeanCan Server

The flexibility of FUSE allows RedBeanPHP to be used as a stand-alone ORM solution, the BeanCan Server


 
 

RedBeanPHP Easy ORM for PHP © 2013 Gabor de Mooij and the RedBeanPHP community - Licensed New BSD/GPLv2