Arbit - project tracking

PHPillow - PHP CouchDB connector

#10: documentArray manipulation

Issue revisions

  • new by Flyingmana at 2010-J-17 9:53
  • assigned by kore at 2011-J-05 13:43
  • closed by kore at 2011-J-05 13:48
Type bug bug
State closed closed
Priority medium medium
Resolution invalid invalid
Assigned to kore
Scheduled for
Affected versions trunk
Affected components Core
Last change Wednesday 5 January 2011 13:48:54 UTC by kore

Short description

If inserted an Array of PhpillowDocument is expected. By Fetching you get an array of _id.

Steps to reproduce

$tempArray = $doc->docArray; $tempArray[] = $docNew;//could not add direct, because _set _get is used(?) $doc->docArray = $tempArray; $doc->save();

Actual behavior

produce an phpillowValidationException: Invalid document type provided

  • Flyingmana at Thursday 17 June 2010 10:03:33 UTC

    have wrote a little workaround till this bug is fixed:

    function addToPhpillowDocumentArray($document, $documentProperty, $addDocument){
            $classname = get_class($addDocument);
            $array = $document->$documentProperty;
            $newArray = array();
            if( is_array($array) ){
                    foreach($array as $value){
                            $tempDocument = new $classname;
                            $newArray[] = $tempDocument->fetchById($value);
                    }
            }
            $newArray[] = $addDocument;
            $document->$documentProperty = $newArray;
    }
    
    
  • kore at Wednesday 5 January 2011 13:48:54 UTC

    You need to do that manually. Imagine that the referenced documents again reference other documents. The following situations could occur and would need to be handled:

    1. Deep object tree: There could be multiple layers of documents, which all then get automatically fetched. Not all documents might be required by the application, thus a fetch limit had to be configured.

    2. Cyclic references: It might always occur that document A references document B, which then again references document A (or even more indirectly). Such cases would need to be handled - this would require an identity session or alike.

    We could implement this by lazy loading of the related documents but there is no functionality for this right now. (Only set the ID n the document and fetch everything else on first property access.) This also might cause lots of queries, entirely transparent to the user, so he / she would not even notice. For retrieval of complex object graphs ("JOIN queries") you'd normally write a view and use ?include_docs=true.