Getting only ID from entity relations without fetching whole object in Doctrine

Don’t complicate your life, you can just do

$food->getFoodGroup()->getId()

This WILL NOT perform any additional query or trigger lazy load!

This is because your $food->foodGroup is a proxy object which knows about it’s ID. It will only do lazy load if you call a getter method of some field which hasn’t been loaded.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)