gpt4 book ai didi

symfony - 使用 DoctrineODM 检索 CouchDb 文档

转载 作者:行者123 更新时间:2023-12-02 14:13:17 30 4
gpt4 key购买 nike

我正在使用这个bundle管理我的数据

我能够创建文档,但无法检索它们我尝试过

    $dm = $this->container->get('doctrine_couchdb.odm.default_document_manager');
$users = $dm->getRepository('myGarageBundle:Utente')->find("781f1ea2e6281beb4ee9ff72b6054af2");

这将检索一个文档,如下所示:

object(my\GarageBundle\CouchDocument\Utente)[303]
private 'id' => string '781f1ea2e6281beb4ee9ff72b6054af2' (length=32)
private 'name' => string 'foo' (length=7)

这没关系。但如果我这样做

$users = $dm->getRepository('myGarageBundle:Utente')->findBy(array('name' => 'foo'));

我有一个空数组。

我的 couchDb 中的文档是

{"_id":"781f1ea2e6281beb4ee9ff72b6054af2","_rev":"1-f89fc2372709de90ab5d1f6cfe6a8f47","type":"my.GarageBundle.CouchDocument.Utente","name":"foo"}

最佳答案

检查这个page

Querying by simple conditions only works for documents with indexed fields.

您必须将其添加到您的实体中

/**
* @CouchDB\Index
* @CouchDB\Field(type="string")
*/
private $name;

The Doctrine persistence interfaces ship with a concept called ObjectRepository that allows to query for any one or set of fields of an object. Because CouchDB uses views for querying (comparable to materialized views in relational databases) this functionality cannot be achieved out of the box. Doctrine CouchDB could offer a view that exposes every field of every document, but this view would only grow into infinite size and most of the information would be useless.

如果您想使用像 findAll() 这样的方法,您必须索引所有文档:

<?php
/** @Document(indexed=true) */
class Person
{
/**
* @Index
* @Field(type="string")
*/
public $name;
}

关于symfony - 使用 DoctrineODM 检索 CouchDb 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31582143/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com