Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix 577 opens up issue with subdocuments and data() calls #732

fellars opened this Issue · 7 comments

3 participants


Reference: Fix #577

I don't think this was what I was hoping for with regard to subdocuments and not indexing. By changing the data() call to have 'indexed' be null and checking if it has a parent, this breaks simple sub arrays

"_id": {"$oid": MongoID("abc")},
"subItems": [{
foreach($item->subItems as $subItem){
    $data = $subItem->data();
    //data is now just an array of the values (array("value"))
   //instead of being indexed array("a"=>"value")
  //that is a pretty big change!!!

My previous notes regarding this issue was the magic of subdocuments using the _id field as the key for non-indexed arrays within subdocuments, not that all subdocument data should not be indexed, which appears to have been the change here.


Ok, can you provide a full example with used schema ?


ok, looks like i figured out what is going on. I have a workaround for my code and it may not be a bug but something that may come up.

If creating an array of array's where the second array is empty, it will get cast into a DocumentSet and not a Document, which is what was causing my problems.


$entity = Model::create();

$entity->items = array(array());

This converts into a DocumentSet of DocumentSets instead of a DocumentSet of Documents (which is what I was thinking I had)

But, if that 2nd layer has any associated data in it, it will create a DocumentSet of Documents instead.

$entity->items = array(array('a'=>true));

I'm good going forward now that I know what is going on and can manage the code on my end to make sure a Document gets created, but wondering if the default in this scenario should be to create Documents if array is empty and not DocumentSets???


It's hard to say if it's a correct behavior or a bug. It essentially depends on the schema you are using for your Model.


Any news on this issue ? Should I tag it to "bug" ?


The type Document or DocumentSet essentially depends of the defined schema.

If you set:

'yourfield' => array('type' => 'object', 'array' => true)

It should be casted to DocumentSet and inner elment to Document whether the content are empty or not.

If you set:

'yourfield' => array('type' => 'object')

it should cast to Document whether the content are empty or not.

@jails jails referenced this issue from a commit
@jails jails Close #732. ec6f75a
@gwoo gwoo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.