Skip to content

Embedded document as _id #1652

Open
Open
@TheHett

Description

@TheHett

Code below works fine:

/**
 * Class UserStats
 * @ODM\Document(collection="user_stats")
 */
class UserStats
{
    /**
     * @ODM\Id(strategy="NONE")
     */
    private $id;

    /** @ODM\Field(type="int") */
    private $downloaded;

    /**
     * @ODM\EmbedOne(targetDocument="core\mongo\keys\UserStatsKey")
     */
    private $test;
    
    //getters and setters
}

result:

> db.user_stats.find().pretty()
{
	"_id" : {
		
	},
	"downloaded" : 10,
	"test" : {
		"id" : 1,
		"date" : ISODate("2017-10-06T09:04:21.557Z")
	}
}

I tried to use Embedded document as primary key:

/**
 * Class UserStats
 * @ODM\Document(collection="user_stats")
 */
class UserStats
{
    /**
     * @ODM\Id(strategy="NONE")
     * @ODM\EmbedOne(targetDocument="core\mongo\keys\UserStatsKey")
     */
    private $id;

    /** @ODM\Field(type="int") */
    private $downloaded;

    //getters and setters
}

result:

octrine\ODM\MongoDB\Mapping\MappingException: No identifier/primary key specified for Document 'core\mongo\entities\UserStats'.

It is not possible?
Id and EmbeddedOne annotations replaced each other.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions