/** * Returns all the beans associated with $bean. * This method will return an array containing all the beans that have * been associated once with the associate() function and are still * associated with the bean specified. The type parameter indicates the * type of beans you are looking for. You can also pass some extra SQL and * values for that SQL to filter your results after fetching the * related beans. * * If 'fearless' mode is on, this method will try to take a shortcut and * use a subquery instead. * * @param RedBean_OODBBean $bean the bean you have * @param string $type the type of beans you want * @param string $sql SQL snippet for extra filtering * @param array $val values to be inserted in SQL slots * * @return array $beans beans yielded by your query. */ public static function related( RedBean_OODBBean $bean, $type, $sql=null, $values=array()) { if (empty($values) && $sql && method_exists(self::$writer,"__fastSelectCritRelated") && !isset($noFearlessCode)) { $idfield = self::$writer->getIDField( $type ); $table = self::$writer->getFormattedTableName($type); $rows = self::$associationManager->related($bean,$type, false, self::$writer->__fastSelectCritRelated($table, $idfield, $sql)); if (count($rows)==0) return array(); return self::convertToBeans($type,$rows); } $keys = self::$associationManager->related( $bean, $type ); if (count($keys)==0) return array(); if (!$sql) return self::batch($type, $keys); $idfield = self::$writer->getIDField( $type ); $sqlSnippet = self::$writer->getSQLSnippetFilter($idfield, $keys, $sql); return self::find( $type, $sqlSnippet, $values ); }