gpt4 book ai didi

symfony - 使用fos:elastica:populate时检测到循环引用

转载 作者:行者123 更新时间:2023-12-02 22:29:41 24 4
gpt4 key购买 nike

到目前为止,我一直使用Groups批注来序列化和填充我的Elastic搜索索引,并且它仅使用“elastica”组中的字段,并且仅用于fos_elastica.yml中列出的Entities,因此运行良好。因此,我可以轻松控制索引中发送了哪个字段,并避免使用循环引用。

现在的问题是,我需要在索引中将某些关系设置为“嵌套”,并且找不到使用组注释的方法,因此我决定在fos_elastica.yml中配置我的类型。

但是现在序列化器想要序列化我不要求他去的字段(或者至少我不认为我是...)

fos_elastica:
serializer: ~
clients:
default:
url: '%elasticsearch.url%'
logger: true
indexes:
alternance:
finder: ~
use_alias: true
index_name: '%elastic_index_name%'
types:
offer:
mappings:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
duration: ~
startat: ~
keywords: ~
email: ~
wage: ~
profile: ~
premiumFlag: ~
idValid: { type: integer }
updated: ~
created: ~
levels:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
diplomas:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
company:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
domains:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
contract:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
city:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
county:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
region:
type: nested
properties:
id: { type: integer }
name: ~
slug: ~
metaTitle: ~
metaDescription: ~
metaKeywords: ~
content: ~
persistence:
driver: orm
model: ModelBundle\Entity\Offer
provider: ~

当我运行bin \ console fos:elastica:populate时,出现此错误:
序列化类“Proxies__CG __ \ ModelBundle \ Entity \ County”的对象时,已检测到循环引用

因此,我假设它正在尝试对County进行序列化,并发现存在OneToMany关系“Cities”,但是在我的配置文件中,我并没有要求他对“Cities”字段进行序列化?

我可以强制序列化程序忽略/不序列化循环引用吗?关于循环引用处理,我所能找到的全部都不在实体类/ yml配置中:(

这是实体配置:

//提供
/**
* @ORM\ManyToOne(targetEntity="City", inversedBy="offers")
* @ORM\JoinColumn(name="city_id", referencedColumnName="id", nullable=false)
*/
private $city;

//城市
/**
* @ORM\ManyToOne(targetEntity="ModelBundle\Entity\County", inversedBy="cities")
* @ORM\JoinColumn(name="county_id", referencedColumnName="id", nullable=false)
*/
private $county;

/**
* @ORM\OneToMany(targetEntity="ModelBundle\Entity\Offer", cascade={"remove"}, mappedBy="city", fetch="EAGER")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
*/
private $offers;

//县
/**
* @ORM\OneToMany(targetEntity="ModelBundle\Entity\City", cascade={"remove"}, mappedBy="county", fetch="EAGER")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
*/
private $cities;

最佳答案

显然只是删除

serializer: ~

l.2解决了问题:D

关于symfony - 使用fos:elastica:populate时检测到循环引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157602/

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