I wonder if there is any way to find out if a record has references.
I have the following entity:
class Item extends Entity
{
/**
* @Id @GeneratedValue
* @Column(name="id")
*/
protected $id;
/**
* @OneToMany(targetEntity="Citation", mappedBy="citation")
*/
protected $citedIn;
/**
* @Column(name="stamped", type="boolean")
*/
protected $stamped;
/** ... rest of the code ... */
}
And I want to perform the following check:
$qb
->select("
COUNT(i.id),
WHEN (i.stamped = true) THEN 'stamped'
WHEN (i.citedIn IS NOT NULL) THEN 'cited'
ELSE 'just started'
END current_status
")
->from(Entity\Item::class, 'i')
->groupBy('current_status');
Note that I tried to use i.citedIn IS NOT NULL
, but it didn't work. What could I use instead?
Since it is a
OneToMany
relationship I think you need to useIS NOT EMPTY
instead ofIS NOT NULL
. Doctrine will create an empty ArrayCollection for each entity, so technically it's not null, because it's an empty array.Update
If that doesn't work, try
NOT INSTANCE OF YourApp\Model\Citation
.