dounuo9921 2017-02-13 16:55
浏览 26
已采纳

Symfony,ODM:如何设置乘法ID注释

So the question is how to provide two or more identifiers keys? I couldn't find any answers on this question in google search... Here is example:

class Customer
{
    /**
     * @ODM\Id
     *
     * @JMS\Expose
     * @JMS\Type("string")
     *
     */
    protected $id;

    /**
     * @var integer
     * @ODM\Id(strategy="INCREMENT")
     *
     * @JMS\Expose
     * @JMS\Type("integer")
     *
     */
    protected $customerId;

So in this case I have second id which increment as I wrote, but first id became null. If I remove and write just * @ODM\Field(type="integer") everything is ok, but no increment of customerId. So how can I have to ids in document? Or I'm wrong and I don't do this?

  • 写回答

2条回答 默认 最新

  • douyimiao1993 2017-02-18 16:57
    关注

    Identifier is automatically mapped as _id field therefore there can be only 1 field mapped as @Id.

    Done similar things in the past and I'd suggest keeping \MongoId as document identifier and generating incremented customerId in your code instead of relying on ODM to do so. Making such generator is pretty straightforward, you need to hook into persisting document (be it in your domain code, which I advice, or leveraging prePersist event) and write generator similar to ODM's IncrementGenerator.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?