We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Did you add your extended user class to extension_packages so the proper user class is instantiated on each request to MODX? Did you make sure you remove the id field and primary key you originally had on the Favorites table?
      • 3749
      • 24,544 Posts
      Also, remember that you have to re-generate the class and map files any time the schema changes.
        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
        • 16059
        • 22 Posts
        Quote from: opengeek at Sep 20, 2013, 10:55 AM
        Did you add your extended user class to extension_packages so the proper user class is instantiated on each request to MODX? Did you make sure you remove the id field and primary key you originally had on the Favorites table?

        Yes I added the extendend user class and removed the id field/primary key. I regenerated the schema and it seems to be working properly ($user = $modx->getObject('extUser', 1); is correctly outputting the userdata). However, when I use the following code to add a Favorite, game_id and user_id are inserted as '0' in the db, but $gameid and $userid do have the right values.

        $userfav = $this->modx->newObject('Favorites',array(
            'game_id' => $gameid,
            'user_id' => $userid
        ));
        $userfav->save();
        


        When I use the following code, the game_id is inserted properly, but the user_id still is inserted as '0'.

        $game = $this->modx->getObject('Game', $gameid);
        $userfav = $this->modx->newObject('Favorites',array(
        	'game_id' => $gameid,
        	'user_id' => $userid,
        	'time' => $now->format('Y-m-d H:i:s'),
        ));
        $game->addMany($userfav);
        $game->save();
        $userfav->save();
        


        • discuss.answer
          • 3749
          • 24,544 Posts
          Some objects don't like having their fields set in newObject(). Try this:

          $userfav = $this->modx->newObject('Favorites');
          $userfav->set('game_id', $gameid);
          $userfav->set('user_id', $userid);
          $userfav->save();
            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
            • 16059
            • 22 Posts
            Quote from: BobRay at Sep 22, 2013, 10:09 PM
            Some objects don't like having their fields set in newObject(). Try this:

            $userfav = $this->modx->newObject('Favorites');
            $userfav->set('game_id', $gameid);
            $userfav->set('user_id', $userid);
            $userfav->save();

            Solved! Thanks for your help
              • 3749
              • 24,544 Posts
              I'm glad you got it sorted. Thanks for reporting back. smiley
                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