I have
$count = $model = OfferType::model()->with('extra','extra.offer', 'extra.version')->count(
"name=:name " .
"AND (version.major=:major OR :major IS NULL) " .
"AND (version.minor=:minor OR :minor IS NULL) " .
"AND (version.patch=:patch OR :patch IS NULL) ",
array(
":name" => $name,
":major" => $major,
":minor" => $minor,
":patch" => $patch,
)
);
Which generates
SELECT COUNT(DISTINCT `t`.`offer_type_id`) FROM `offer_type` `t` INNER JOIN `offer_type_extra` `extra` ON (`extra`.`offer_type_id`=`t`.`offer_type_id`) INNER JOIN `offer` `offer` ON (`offer`.`offer_type_extra_id`=`extra`.`offer_type_extra_id`) INNER JOIN `version` `version` ON (`extra`.`version_id`=`version`.`version_id`) WHERE (name='test type 1' AND (version.major='3' OR '3' IS NULL) AND (version.minor='0' OR '0' IS NULL) AND (version.patch='0' OR '0' IS NULL) )
I want it too generate
SELECT COUNT(`t`.`offer_type_id`) FROM `offer_type` `t` INNER JOIN `offer_type_extra` `extra` ON (`extra`.`offer_type_id`=`t`.`offer_type_id`) INNER JOIN `offer` `offer` ON (`offer`.`offer_type_extra_id`=`extra`.`offer_type_extra_id`) INNER JOIN `version` `version` ON (`extra`.`version_id`=`version`.`version_id`) WHERE (name='test type 1' AND (version.major='3' OR '3' IS NULL) AND (version.minor='0' OR '0' IS NULL) AND (version.patch='0' OR '0' IS NULL) )
The only difference is the removal of distinct.
How do I achieve this?