Get a single entity from a collection of magento models

I ran into a problem because I am sure that I will not do it correctly with my programming.
I created a custom model in Magento.
In the database table of my model there are several objects with the same attributes ...
I need to select only one of all these objects with the same attribute that I have.
At the moment, I have done this:

$myvariable = Mage::getModel('test/test')->getCollection()
->setOrder('idserialkeys', 'asc')
->addFilter('idproduit', 1)
->addFilter('utilise', 0)
->addFilter('customerid', 0)
->addFilter('numcommande', 0)

I have about a hundred results from this download, but I only need to update one of them, so right after that:

->setPageSize(1);

The problem is what I need foreachafter updating my object

foreach($mavaribale as $modifiemoi) {
    // Update of my entity because of course there is only one 
}

, ( ), setPagesize... .

,

+5
2

, , getFirstItem. :

$modifiemoi = $myvariable->getFirstItem();

, setPageSize, .

, !

,

+19

Varien_Data_Collection, getFirstItem:

$modifiemoi = $mavaribale->getFirstItem();
+11

All Articles