views:

26

answers:

1

I'm using Doctrine 2 ODM (with MongoDB).

My Document model:

class Users_Model_User
{
    public $id;
    public $username;
    public $password;
    public $myRuntimeProperty = 'some value';
}

My Document mapping in YAML:

Users_Model_User:
db: my_db
collection: users
fields:
    id:
        fieldName: id
        id: true
    username:
        fieldName: username
        type: string
    password:
        fieldName: password
        type: string

My test code:

$user = new Users_Model_User;
$user->username = 'hello';
$user->password = 'world';
$this->dm->persist($user);
$this->dm->flush();

$user = $this->dm->findOne('Users_Model_User', array('username' => 'hello'));

Zend_Debug::dump($user);

My result:

object(Users_Model_User)#81 (4) {
  ["id"] => string(24) "4c1d5eb68ead0eb332000000"
  ["username"] => string(5) "hello"
  ["password"] => string(5) "world"
  ["myRuntimeProperty"] => string(10) "some value"
}

How do I make it so that "myRuntimeProperty" does not get saved with my document? My models are being saved with all properties including things like "_propertyChangedListeners" which is messing everything up when the model gets reloaded.

A: 

Never used Doctrine, but it looks like one of two things is happening:

  1. Doctrine has a pretty serious bug and is ignoring your YML definitions.
  2. You're not "hooking up", the YML files.

Looking at the docs, it seems like you need some extra "magic" here:

$driver = new YamlDriver(array('/path/to/files'));
$config->setMetadataDriverImpl($driver);

Could this be your issue?

Gates VP