【发布时间】:2017-05-19 19:39:38
【问题描述】:
我正在尝试计算实体中有多少字段不为空。具体来说,如果属性是ArrayCollection,判断collection是否不为空。
我在这里获取所有用户对象属性
$properties = $em->getClassMetadata('AppBundle:User')->getFieldNames();
$output = array_merge(
$properties,
$em->getClassMetadata('AppBundle:User')->getAssociationNames()
);
foreach($output as $property){
????
}
关于如何遍历实体属性并计算非空或非空属性的问题。
var_dump($output) 输出:
array (size=47)
0 => string 'username' (length=8)
1 => string 'usernameCanonical' (length=17)
2 => string 'email' (length=5)
3 => string 'emailCanonical' (length=14)
...
45 => string 'expertise' (length=13) // ManyToOne association
46 => string 'reports' (length=7) // OneToMany association. type ArrayCollection
【问题讨论】:
标签: php symfony doctrine-orm doctrine