PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 6, 2022

[FIXED] Doctrine2 ODM - Object ( or Embedded Document ) as _id

 February 06, 2022     doctrine-odm, doctrine-orm, mongodb, symfony     No comments   

Issue

I have a process running an incremental map reduce to a collection where I am looking at metrics over different time periods - grouping by id(s) and date. So my output collection essentially has a composite id to handle the grouping.

{
    "_id" : {
        "site" : 67,
        "dt" : ISODate("2012-07-03T00:00:00Z")
    },
    "value" : {
        // Metrics here
    }
}

I want to be able to fetch results from this collection in my Symfony2 app using the ODM - but having trouble with the _id field. I thought I might be able to specify it as an @Id and @embedOne:

   /**
    * @MongoDB\Id
    * @MongoDB\EmbedOne(targetDocument="reportId")
    */
   protected $id;

However, this doesn't work. I also tried setting @Id with strategy=NONE, and I can use the QueryBuilder to fetch rows, but it errors when trying to hydrate my Document class. I tried slugging the site id and date ( 67-134137916 ) and it allows me to use the DocumentManager, but I lose the ability to query by date ranges.

Anyone have any input on how to handle an object as an id in Doctrine2's ODM, is this supported?

edit: Removed composite primary key tag - question really pertains to using an object as a primary key.


Solution

I'm not sure if this gets at the heart of your question: Composite Primary Keys tutorial

It looks like you can only have composite primary keys of integers and strings (so no dates?).



Answered By - Jenna
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing