Magento 1.9 – How to Get Primary Key of Collection Objects

custom-collectionmagento-1.9

I have a collection of attributes which was made by combining several tables. I want to get the primary key of the objects resides in this collection. Any suggestions would be helpful,

Best Answer

Whenever you have an item from a collection calling ->getId() on the item will return the primary key value of that item.

To get the name of the field from a certain collection the following snippet should help

$collection = Mage::getModel('namespace/...')->getCollection();
echo $collection->getResource()->getIdFieldName();
Related Topic