RedBeanPHP\AssociationManager::relatedCount PHP Method

relatedCount() public method

This method returns the number of beans of type $type associated with reference bean(s) $bean. The query can be tuned using an SQL snippet for additional filtering.
public relatedCount ( redbeanphp\OODBBean | array $bean, string $type, string $sql = NULL, array $bindings = [] ) : integer
$bean redbeanphp\OODBBean | array a bean object or an array of beans
$type string type of bean you're interested in
$sql string SQL snippet (optional)
$bindings array bindings for your SQL string
return integer
    public function relatedCount($bean, $type, $sql = NULL, $bindings = array())
    {
        if (!$bean instanceof OODBBean) {
            throw new RedException('Expected array or OODBBean but got:' . gettype($bean));
        }
        if (!$bean->id) {
            return 0;
        }
        $beanType = $bean->getMeta('type');
        try {
            return $this->writer->queryRecordCountRelated($beanType, $type, $bean->id, $sql, $bindings);
        } catch (SQLException $exception) {
            $this->handleException($exception);
            return 0;
        }
    }