Skip to content

Loading…

Embedded doc containing embedded array of docs #57

Open
jmper opened this Issue · 2 comments

2 participants

@jmper

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.

@ahirmayur

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 {
.
.
.
}

@ahirmayur

Any progress for Validation in Array of Embedded Documents?

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.