/** * @param array $options * @param object $joinDependency * @param array $bindVars * @return string */ protected function _constructFinderSqlForAssocLimiting($options, $joinDependency, $bindVars) { $isDistinct = $this->_includeEagerConditions($options) || $this->_includeEagerOrder($options); $sql = "SELECT "; if ($isDistinct) { $sql .= $this->connection->distinct($this->tableName() . '.' . $this->primaryKey()); } else { $sql .= $this->primaryKey(); } $sql .= ' FROM ' . $this->tableName() . ' '; // add join tables/conditions/ordering if ($isDistinct) { $sql .= $this->_constructAssociationJoinSql($joinDependency); } $sql = $this->_addConditions($sql, $options['conditions']); if (!empty($options['order'])) { if ($isDistinct) { $sql = $this->connection->addOrderByForAssocLimiting($sql, $options); } else { $sql .= "ORDER BY " . $options['order']; } } $sql = $this->connection->addLimitOffset($sql, $options); return $this->sanitizeSql($sql, $bindVars); }