Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Null _rev passed to CouchDB #88

Open
SteveTalbot opened this issue Feb 20, 2014 · 0 comments
Open

Null _rev passed to CouchDB #88

SteveTalbot opened this issue Feb 20, 2014 · 0 comments

Comments

@SteveTalbot
Copy link

We tried mapping the CouchDB _rev string to a PHP property. The line we used in the XML mapping file was:

<field name="etag" type="string" version="true" json-name="_rev"></field>

This works when fetching a document from the database, but it fails when trying to persist a new document to the database.

The problem is in Doctrine\ODM\CouchDB\UnitOfWork::flush() where the field values are converted to JSON values. The _rev version field is included in the JSON, even if it is null. This results in a 400 bad request response from CouchDB.

Our workaround is to replace line 1072 with the following code snippet:

$jsonName = $class->fieldMappings[$fieldName]['jsonName'];
if( $jsonName != '_rev' || $fieldValue ) $data[$jsonName] = $fieldValue;

Rather than testing the JSON name, it might be more consistent with the rest of your design to test $class->fieldMappings[$fieldName]['isVersionField'] or to check whether $fieldName is equal to $class->versionField.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant