到目前为止,我一直使用Groups注释来序列化和填充我的弹性搜索索引,它工作得很好,因为它只使用了组中的字段" elastica",并且只针对列出的实体在我的fos_elastica.yml中。因此,我可以轻松控制在索引中发送的字段,并避免循环引用。
现在的问题是我需要设置一些关系"嵌套"在我的索引中,并且无法通过组注释找到如何执行此操作,因此我决定在我的fos_elastica.yml中配置我的类型......
但是现在Serializer想要序列化我不会问他的字段(或者至少我不认为我是......)
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"
所以我假设它正在尝试序列化郡,并发现有一个OneToMany关系" Cities",但在我的配置文件中我并不是在询问他将序列化城市"领域?
我可以强制序列化程序忽略/不序列化循环引用吗?我所能找到的关于循环引用处理的所有内容都不在实体类/ yml配置中:(
以下是实体配置:
// OFFER
/**
* @ORM\ManyToOne(targetEntity="City", inversedBy="offers")
* @ORM\JoinColumn(name="city_id", referencedColumnName="id", nullable=false)
*/
private $city;
// 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;
// COUNTY
/**
* @ORM\OneToMany(targetEntity="ModelBundle\Entity\City", cascade={"remove"}, mappedBy="county", fetch="EAGER")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
*/
private $cities;
答案 0 :(得分:0)
显然只是删除了
serializer: ~
l.2修正了问题:D