0

I've installed the FOSUserBundle on Symfony 2 for MongoDB and I would like to add some custom fields but they are always empty.

My UserBundle:

<?php
namespace Skurty\UserBundle\Document;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document(
 *     collection="user"
 * )
 */
class User extends BaseUser
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $test;

    public function setTest($test)
    {
        $this->test = $test;
    }

    public function getTest()
    {
        return $this->test;
    }
}

A controller (not in the same bundle that the UserBundle):

$user = $this->getUser();

// or

$user = $this->get('doctrine_mongodb')
    ->getRepository('SkurtyUserBundle:User')
    ->find(new \MongoId('...'));

// $user->getUsername() => 'skurty'
// $user->getTest() => null

And the MongoDB document:

{ "_id" : ObjectId("..."), "username" : "skurty", /* FOSUserBundle fields */, "test" : "abc" }

What is wrong?

Thank you

2
  • did you clear your cache? This might be a result-cache issue. Commented May 15, 2014 at 15:11
  • It was that and I totally forgot to look at it (I only updated the mongodb schema)... So problem solved, thank you ! Commented May 15, 2014 at 15:29

1 Answer 1

2

You need to update your database schema and clear your cache for the changes to take effect.

Otherwise you may end up receiving cached results that don't reflect the current data in the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.