purekid / mongodm

MongoDB ORM that includes support for references,embed and multilevel inheritance.
MIT License
200 stars 47 forks source link

Embedding: where's the id of the embedded object? #100

Closed falco442 closed 4 years ago

falco442 commented 6 years ago

Hi! I was trying to save with embedded models, but I cannot retrieve the MongoId of the embedded object. My case is:

<?php
namespace Demo;

require 'vendor/autoload.php';

use Purekid\Mongodm\Model;

class Human extends Model{

    static $collection = "human";

    protected static $attrs = array(
        'name' => array('default'=>'anonym','type'=>'string'),
        'dad' =>  array('type'=>'embed','model'=>'Demo\Human'),
        'mum' =>  array('type'=>'embed','model'=>'Demo\Human'),
    );

}

$bob = new Human( array('name'=>'Bob') );
$bob->save();

$lisa = new Human( array('name'=>'Lisa') );
$lisa->save();

$david = new Human( array('name'=>'David') );
$david->save();

$bob->dad = $david;
$bob->mum = $lisa;

$bob->save();

$bob = Human::one( array("name"=>"Bob") );

print_r($bob->toArray());

I was expected to see the MongoId objects into the mum and dad objects, but I see this

Array
(
    [_id] => MongoId Object
        (
            [objectID:MongoId:private] => MongoDB\BSON\ObjectId Object
                (
                    [oid] => 5accb8a7c9153174bb3fe532
                )

        )

    [name] => Bob
    [dad] => Array
        (
            [name] => David
            [age] => 42
            [gender] => male
        )

    [mum] => Array
        (
            [name] => Lisa
            [age] => 41
            [gender] => female
        )

)

How can I see the MongoId id of the embedded objects? It seems that doesn't save them..

EmilSabitov commented 4 years ago

Same issue. @falco442 , you solved this?

jrschumacher commented 4 years ago

@EmilSabitov I think you should probably look at a new ORM. This hasn't been updated in years and could contain vulnerabilities.

EmilSabitov commented 4 years ago

@jrschumacher , after i sent message, i checked dates of last commits and began to search other libs. So sad, because this lib was so light and fast ;/

jrschumacher commented 4 years ago

Closing since this project is not maintained