我需要弹性上传,当我创建实体主管时,只有具有状态批准的人,这是我的,映射:
persistence:
driver: orm
model: Artel\ProfileBundle\Entity\Lead
provider:
query_builder_method: createIsActiveQueryBuilder
listener: ~
finder: ~
和我的query_builder_method:createIsActiveQueryBuilder:
public function createIsActiveQueryBuilder()
{
$qb = $this->getEntityManager()->createQueryBuilder('d');
$qb
->select('d')
->from('ArtelProfileBundle:Lead', 'd')
->where('d.statusLead = :status')
->setParameter('status', 'approved')
;
return $qb;
}
当我开始运行时,我上传了仅限领导状态
app/console fos:elastica:populate --no-reset
创建了潜在客户
$lead = new Lead();
//some logic
$manager->persist($lead);
$manager->flush();
但是当我创建默认状态为'not_approved'的新潜在客户时,这个潜在客户上传了弹性,为什么我不理解监听器上传这个潜在客户,为什么不工作query_builder?
答案 0 :(得分:0)
我添加到弹性配置indexable_callback并在实体类中创建功能isPublished,当我创建状态为not_approved的新潜在客户时,此潜在客户不会弹性上传。这非常好 - 当我更改状态'已批准'时 - 导致弹性上传,然后我更改状态为not_approved并且导致删除弹性。这是WIN
public function isPublished()
{
if ($this->getStatusLead() === self::STATE_TO_BE_INDEXED_IN_ELA) {
return true;
}
return false;
}
lead:
finder: ~
types:
lead:
indexable_callback: 'isPublished'
mappings:
id:
type: integer
persistence:
driver: orm
model: Artel\ProfileBundle\Entity\Lead
provider:
query_builder_method: createIsActiveQueryBuilder
listener: ~
finder: ~