Property | Type | Description | |
---|---|---|---|
$redbean | redbeanphp\OODB | ||
$toolbox |
Method | Description | |
---|---|---|
__construct ( |
Constructor. | |
find ( string $type, string $sql = NULL, array $bindings = [] ) : array | Finds a bean using a type and a where clause (SQL). | |
findAndExport ( string $type, string $sql = NULL, array $bindings = [] ) : array | Like find() but also exports the beans as an array. | |
findCollection ( string $type, string $sql, array $bindings = [] ) : redbeanphp\BeanCollection | Finds a BeanCollection using the repository. | |
findLast ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\OODBBean | Like find() but returns the last bean of the result array. | |
findLike ( string $type, array $conditions = [], string $sql = '' ) : array | Finds beans by its type and a certain criteria set. | |
findMulti ( string | array $types, $sql, array $bindings = [], array $remappings = [], string $queryTemplate = ' %s.%s AS %s__%s' ) : array | Returns a hashmap with bean arrays keyed by type using an SQL query as its resource. Given an SQL query like 'SELECT movie.*, review.* FROM movie. | |
findOne ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\OODBBean | Like find() but returns just one bean instead of an array of beans. | |
findOrCreate ( string $type, array $like = [] ) : redbeanphp\OODBBean | Finds or creates a bean. | |
findOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : array | Tries to find beans of a certain type, if no beans are found, it dispenses a bean of that type. |
public __construct ( |
||
$toolbox |
public find ( string $type, string $sql = NULL, array $bindings = [] ) : array | ||
$type | string | type the type of bean you are looking for |
$sql | string | sql SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | array |
public findAndExport ( string $type, string $sql = NULL, array $bindings = [] ) : array | ||
$type | string | type the type of bean you are looking for |
$sql | string | sql SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | array |
public findCollection ( string $type, string $sql, array $bindings = [] ) : redbeanphp\BeanCollection | ||
$type | string | the type of bean you are looking for |
$sql | string | SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | redbeanphp\BeanCollection |
public findLast ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\OODBBean | ||
$type | string | the type of bean you are looking for |
$sql | string | SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | redbeanphp\OODBBean |
$stuff = $finder->findMulti('movie,review', '
SELECT movie.*, review.* FROM movie
LEFT JOIN review ON review.movie_id = movie.id');
After this operation, $stuff will contain an entry 'movie' containing all
movies and an entry named 'review' containing all reviews (all beans).
You can also pass bindings.
If you want to re-map your beans, so you can use $movie->ownReviewList without
having RedBeanPHP executing an SQL query you can use the fourth parameter to
define a selection of remapping closures.
The remapping argument (optional) should contain an array of arrays.
Each array in the remapping array should contain the following entries:
array(
'a' => TYPE A
'b' => TYPE B
'matcher' => MATCHING FUNCTION ACCEPTING A, B and ALL BEANS
'do' => OPERATION FUNCTION ACCEPTING A, B, ALL BEANS, ALL REMAPPINGS
)
Using this mechanism you can build your own 'preloader' with tiny function
snippets (and those can be re-used and shared online of course).
Example:
array(
'a' => 'movie' //define A as movie
'b' => 'review' //define B as review
'matcher' => function( $a, $b ) {
return ( $b->movie_id == $a->id ); //Perform action if review.movie_id equals movie.id
}
'do' => function( $a, $b ) {
$a->noLoad()->ownReviewList[] = $b; //Add the review to the movie
$a->clearHistory(); //optional, act 'as if these beans have been loaded through ownReviewList'.
}
)
The Query Template parameter is optional as well but can be used to
set a different SQL template (sprintf-style) for processing the original query. public findMulti ( string | array $types, $sql, array $bindings = [], array $remappings = [], string $queryTemplate = ' %s.%s AS %s__%s' ) : array | ||
$types | string | array | a list of types (either array or comma separated string) |
$bindings | array | optional, bindings for SQL query |
$remappings | array | optional, an array of remapping arrays |
$queryTemplate | string | optional, query template |
return | array |
public findOne ( string $type, string $sql = NULL, array $bindings = [] ) : redbeanphp\OODBBean | ||
$type | string | type the type of bean you are looking for |
$sql | string | sql SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | redbeanphp\OODBBean |
public findOrCreate ( string $type, array $like = [] ) : redbeanphp\OODBBean | ||
$type | string | type of bean to search for |
$like | array | criteria set describing bean to search for |
return | redbeanphp\OODBBean |
public findOrDispense ( string $type, string $sql = NULL, array $bindings = [] ) : array | ||
$type | string | the type of bean you are looking for |
$sql | string | SQL query to find the desired bean, starting right after WHERE clause |
$bindings | array | values array of values to be bound to parameters in query |
return | array |