1

join query with customer table getSize() count mismatch with the mysql db result.

Query
-----
$collection = Mage::getModel('customer/customer')->getCollection();
$collection->getSelect()->join(array('endorsement'=>'flendorsement'),'e.entity_id = endorsement.to_user_id',array('total_endorsement'=>'COUNT(endorsement.endorsement_id)'));
            $collection->getSelect()->group('endorsement.to_user_id');

When i execute this query in mysql phpmyadmin, there will show the 3rows,
but  getSize() method return "2"

see the screen below:

enter image description here

senthil
  • 1,729
  • 2
  • 26
  • 54

1 Answers1

4

Use this

$collection->count();

For getSize() the collection is not loaded. For count() it is.

Check the difference between getSize() and count() from here Difference between getSize() and count() on collection

Manashvi Birla
  • 8,833
  • 9
  • 27
  • 53
  • the getCount() is used in custom table collection, but here i wrote the query with Magento table, that's why i am using getSize(),then i have a pagination issues also with the group by query, for your further reference i attached the screen. – senthil Jul 14 '15 at 06:47
  • getSize() does not load the collection for records that come from the data base. you need to override the method and tell it to load the collection – Manashvi Birla Jul 14 '15 at 06:54
  • How can i override the getSize(),can you explain that or having any tutorial for getSize() override? – senthil Jul 14 '15 at 07:01
  • TRy this http://ka.lpe.sh/2012/01/05/magento-wrong-count-in-admin-grid-when-using-group-by-clause-overriding-lib-module/ it might help you – Manashvi Birla Jul 14 '15 at 07:05
  • thanks for your support,now its working. then i have one more problem, i posted the question see the link http://magento.stackexchange.com/questions/74278/magento-join-query-with-group-by-and-having-error?noredirect=1#comment98326_74278 – senthil Jul 14 '15 at 07:23