We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24629
    • 370 Posts
    Hi,
    I've created custom tables with Bob's guides (https://bobsguides.com/custom-db-tables.html) and that works fine. my class is called 'Vote'

    Now i want to remove/delete the whole collection (votes) in that custom table using
    $modx->removeCollection( 'vote', array() );

    But that does not seem to work. in the error log i see
    Could not get table name for class: vote

    and
     xPDO->removeCollection - Error deleting vote instances using query DELETE FROM  


    I did do the addpackage on top of my script and that works fine
    $modx->addPackage( 'vote', $path . 'model/', 'lhm_' );


    anyone know what i'm doing wrong? or is removeCollection not meant for custom classes?

    Tnx
    RDG

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      Did you try this:

      $modx->removeCollection('vote');


      The existence of the second argument may be confusing things.

      Also try 'Vote' instead of 'vote'.

      Check the return value of addPackage(). It will be empty if it fails.

      If everything else fails, you can try this:

      $votes = $modx->getCollection('Vote');
      
      if (empty($votes) || count($votes) < 1) {
         return 'failed to get votes';
      } else {
         foreach ($votes as $vote) {
             $vote->remove();
         }
      }
      

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 24629
        • 370 Posts
        Hi, the capital V was the culprit
        Tnx