protected static function buildWhereForRelatedAttributeThatIsItselfAHasManyRelation(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, $joinTablesAdapter, $relationAttributeTableAliasName, $operatorType, $value, &$where, $whereKey) { assert('$joinTablesAdapter instanceof RedBeanModelJoinTablesQueryAdapter'); assert('is_string($relationAttributeTableAliasName)'); assert('is_string($operatorType)'); assert('is_array($value) && count($value) > 0'); assert('is_array($where)'); assert('is_int($whereKey)'); $relationAttributeName = $modelAttributeToDataProviderAdapter->getRelatedAttribute(); $relationAttributeModelClassName = $modelAttributeToDataProviderAdapter->getRelatedAttributeRelationModelClassName(); if ($relationAttributeModelClassName != 'CustomFieldValue') { //Until we can add a third parameter to the search adapter metadata, we have to assume we are only doing //this for CustomFieldValue searches. Below we have $joinColumnName, since we don't have any other way //of ascertaining this information for now. throw new NotSupportedException(); } if ($operatorType != 'oneOf') { //only support oneOf for the moment. Once we add allOf, need to have an alternative sub-query //below that uses if/else logic to compare count against how many possibles. then return 1 or 0. } $relationAttributeTableName = RedBeanModel::getTableName($relationAttributeModelClassName); $tableAliasName = $relationAttributeTableName; $joinColumnName = 'value'; $relationColumnName = RedBeanModel::getTableName($modelAttributeToDataProviderAdapter->getRelatedAttributeModelClassName()) . "_id"; $quote = DatabaseCompatibilityUtil::getQuote(); $where[$whereKey] = "(1 = (select 1 from {$quote}{$relationAttributeTableName}{$quote} {$tableAliasName} " . "where {$quote}{$tableAliasName}{$quote}.{$quote}{$relationColumnName}{$quote} = " . "{$quote}{$relationAttributeTableAliasName}{$quote}.id " . "and {$quote}{$tableAliasName}{$quote}.{$quote}{$joinColumnName}{$quote} " . DatabaseCompatibilityUtil::getOperatorAndValueWherePart($operatorType, $value) . " limit 1))"; }