We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17499 ☆ A M B ☆
    • 872 Posts
    ok smiley
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: lossendae at Mar 29, 2011, 01:49 PM

      English was misused here ?
      What whatnot means ?

      Seriously, i’m lost... :p
      Sorry lossendae—lost in translation indeed.

      Your phrase:
      Quote from: lossendae at Mar 29, 2011, 11:31 AM

      Does it worth a feature request ?
      should actually be

      Is it worth a feature request ?
      And I was simply poking fun at your misused grammar.

      Finally, a definition of whatnot — http://www.google.com/dictionary?langpair=en|en&q=whatnot&hl=en&aq=f
        • 17499 ☆ A M B ☆
        • 872 Posts
        I didn’t take it badly, I can improve myself only if I am guided one way or another smiley
          • 24865
          • 289 Posts
          Seconded on the updateCollection feature, that would be seriously helpful. Otherwise (for those who still need it), I would solve it like so:

          $stack = $modx->getCollection('modelName', array(
          	'key' => 'value'
          ));
          
          foreach($stack as $object) {
          	$object->set('key', 'value2');
          	$object->save();
          }
          
          // or
          
          foreach($stack as $object) {
          	$object->fromArray(array(
          		'key' => 'value2',
          		'editedon' => time()
          	));
          
          	$object->save();
          }


          // Edit: code-wise I don’t like it, but I think it’s possible.
          $stack = $modx->getCollection('modelName', array(
          	'key' => 'value'
          ));
          
          foreach($stack as $object) {
          	$object->set('key', 'value2')->save();
          }


          Hope this helps! smiley

          @Jason; hehe. :-P
            @MarkGHErnst

            Developer at Adwise Internetmarketing, the Netherlands.
            • 21257 MODX Staff
            • 730 Posts
            They are, because getCollection returns an array of xPDO objects.
            You do have to ->save() each of them however.

            Alternately, if you have a relationship where there is a parent for all of these objects, you could load them with ->getMany(), iterate the array, update each object, then just call ->save() on the parent object.
              Mike Schell
              Lead Developer, MODX Cloud
              Email: [email protected]
              GitHub: https://github.com/netProphET/
              Twitter: @mkschell
              • 24865
              • 289 Posts
              Oh crap indeed netProphET! I forgot all about ->save(); See, $stack litteraly returns a STACK of OBJECTS in ARRAY format. Looping over them would push a single object (row in MySQL) into the variable which you can manipulate to your wishes (within reason, of course).

              I updated my example with the ->save();
                @MarkGHErnst

                Developer at Adwise Internetmarketing, the Netherlands.
                • 17499 ☆ A M B ☆
                • 872 Posts
                @reSpawN

                I updated my message with the remove button smiley
                  • 24865
                  • 289 Posts
                  Alright! I also added a small quick save function but I am not sure if it works.

                  ->set(’key’, ’value’)->save();

                  This only works if the set() function returns the specified object. smiley
                    @MarkGHErnst

                    Developer at Adwise Internetmarketing, the Netherlands.
                    • 21257 MODX Staff
                    • 730 Posts
                    https://github.com/modxcms/xpdo/blob/master/xpdo/om/xpdoobject.class.php
                    ->set returns boolean Determines whether the value was set successfully and was determined to be dirty (i.e. different from the previous value).
                      Mike Schell
                      Lead Developer, MODX Cloud
                      Email: [email protected]
                      GitHub: https://github.com/netProphET/
                      Twitter: @mkschell
                      • 24865
                      • 289 Posts
                      Oh yes of course, that’s pretty logical since I often use it in the if ($object->save()) { method.
                        @MarkGHErnst

                        Developer at Adwise Internetmarketing, the Netherlands.