Don't complicate your life, you can just do
$food->getFoodGroup()->getId()
This WILL NOT perform any additional query or trigger lazy load!
Why? 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…