I have a simple problem where I often return CRUD type Ajax requests with array serialized versions of Doctrine 1.2 models. I’d love to be able to simply return the toArray() method after the execute() result, however, this will display data about my models that I don’t wish to expose. A simple example is on my user model the password and salt get displayed. While I realize those are already hashed values, it’s something I’d rather not return as a JSON response.
I’ve poured over the Doctrine 1.2 manual, but did not find anything that offered the type of functionality I’m looking for. I realize I can iterate over the result to manually unset() the columns I wish to hide, but I’m hoping a more native solution is out there that I’ve overlooked.
Why don’t you build your own
toArray()?If you want to do that, you will have to extends the sfDoctrineRecord class that inherit from all Base* class. It is describe in the doc.
You have to put the
configureDoctrine()insideconfig/ProjectConfiguration.class.php.Then you will have a class like that:
So you can easily add your custom
toArray()here:So, when using the
toArray()method with an array of fields for the third parameters, they will be excluded from the result.