gpt4 book ai didi

php - Symfony2 和 MongoDB : FormType of a document with references

转载 作者:可可西里 更新时间:2023-11-01 09:55:37 25 4
gpt4 key购买 nike

我的其中一份表格有问题。我有一个链接到其他 3 个文档的“资源”文档:

  • 标签(引用很多)
  • 类别(ReferenceOne)
  • 数据存储库(ReferenceOne)

这是我的文档的定义:

class Resource {

/**
* @MongoDB\Id
*/
private $id;

/**
* @MongoDB\String
*/
private $name;

/**
* @MongoDB\String
*/
private $description;

/**
* @MongoDB\ReferenceMany(targetDocument="Tag")
*/
protected $tags;

/**
* @MongoDB\ReferenceOne(targetDocument="Category")
*/
private $category;

/**
* @MongoDB\ReferenceOne(targetDocument="DataRepository")
*/
private $dataRepository;

/**
* @MongoDB\file
*/
private $logo;

/**
* @MongoDB\Boolean
*/
private $available;

这是我的“资源”文档的 formType:

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('description');
$builder->add('logo', 'file');
$builder->add('available', 'checkbox');
$builder->add('category', 'document', array(
'class' => 'AppBundle:Category'
));
$builder->add('tags', 'document', array(
'class' => 'AppBundle:Tag',
'multiple' => 'true'
));
$builder->add('dataRepository', "document", array(
'class' => 'PortailCatalogBundle:DataRepository'
));
}

生成的表单是完美的,但是当我提交它时,它似乎并没有像异常(exception)那样滋润我的实体。这是请求:

["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#7 (1) {
["parameters":protected]=>
array(1) {
["resource"]=>
array(7) {
["name"]=>
string(14) "Ressource N°1"
["description"]=>
string(28) "Juste un test parmi d'autres"
["available"]=>
string(1) "1"
["category"]=>
string(24) "551c02b5a246cb287c09bcde"
["tags"]=>
array(2) {
[0]=>
string(24) "551c02b5a246cb287c09bcdc"
[1]=>
string(24) "551d0ac2a246cbe40809bc97"
}
["dataRepository"]=>
string(24) "551d650aa246cb700e09bc9d"
["_token"]=>
string(40) "4adfcc295b2305c784347311d3bbad55c260c6ed"
}
}
}

所有这些 objectId 都是正确的,但是在提交时,表单会为这 3 个文档生成错误,错误为“此值无效。

我发现查询是在提交表单后立即完成的:

db.category.find({ "_id": ObjectId("551e66a2a246cba51909bc9c") });
db.tag.find({ "_id": ObjectId("551e66a2a246cba51909bc9d") });
db.dataRepository.find({ "_id": ObjectId("551e66a2a246cba51909bc9e") });

如您所见,objectId 不匹配。我觉得我搞砸了 formType 定义部分。

我没有在 DoctrineMongoDBBundle 中找到任何关于这种形式的文档......任何想法或文档链接?

谢谢。

最佳答案

我的源代码没有任何错误。我对 doctrine/doctrine-odm 包进行了 Composer 更新,表格按预期工作(显然添加了包的提交)。

关于php - Symfony2 和 MongoDB : FormType of a document with references,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487245/

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