Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Embedded doc containing embedded array of docs #57

Open
jmper opened this issue Sep 22, 2011 · 2 comments
Open

Embedded doc containing embedded array of docs #57

jmper opened this issue Sep 22, 2011 · 2 comments

Comments

@jmper
Copy link

jmper commented Sep 22, 2011

With the following configuration:

class Test extends EMongoDocument {
    public function embeddedDocuments() {
        return array('test1' => 'Test1'),
    }
}

class Test1 extends EMongoEmbeddedDocument {
    public $test2;

    public function behaviors() {
        return array(
            'test2Behavior => array(
                'class'=>'ext.mongodb.extra.EEmbeddedArraysBehavior',
                'arrayPropertyName'=>'test2',       // name of property, that will be used as an array
                'arrayDocClassName'=>'Test2'    // class name of embedded documents in array
            ),
        ),
    }
}

class Test2 extends EMongoEmbeddedDocument {
    public $property1;
}

I cannot access:

$test = Test::model()->findByPk($id);
$val = $test->test1->test2[0]->property1;

actually I can do the following:

$val = $test->test1->test2[0]['property1'];

i.e. arrays are not being converted to objects.

@BorderlessNomad
Copy link

I am facing the same problem...

http://pastebin.com/raw.php?i=wmBydGSR

{User extends EMongoDocument

{CompensationBasic extends EMongoEmbeddedDocument
    {CompensationAllowances extends EMongoEmbeddedDocument
        type:
        amout:
    }
    {CompensationDeductions extends EMongoEmbeddedDocument
        type:
        amout:
    }
}

}

class User extends EMongoDocument { // User Model

public $compensation;
.
.
public function behaviors() {
return array(
array(
'class' => 'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',
'arrayPropertyName' => 'compensation', // name of property, that will be used as an array
'arrayDocClassName' => 'CompensationBasic' // class name of embedded documents in array
),
);
}
.
.
}

class CompensationBasic extends EMongoEmbeddedDocument {
public $allowances;
public $deductions;
.
.
.
public function behaviors() {
return array(
array(
'class' => 'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',
'arrayPropertyName' => 'allowances', // name of property, that will be used as an array
'arrayDocClassName' => 'CompensationAllowances' // class name of embedded documents in array
),
array(
'class' => 'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',
'arrayPropertyName' => 'deductions', // name of property, that will be used as an array
'arrayDocClassName' => 'CompensationDeductions' // class name of embedded documents in array
),
);
}
.
.
}

class CompensationAllowances extends EMongoEmbeddedDocument {
.
.
.
}

class CompensationDeductions extends EMongoEmbeddedDocument {
.
.
.
}

@BorderlessNomad
Copy link

Any progress for Validation in Array of Embedded Documents?

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

2 participants