The idiom is generally phrased “have your cake and eat it too” but yeah that’s rather confusing. The way you said it is how I actually understand it in my head.
I think the way English Common has evolved doesn’t help either, because “to have” is now synonymous with “to eat” in the context of food, but I don’t think it was that way when the idiom was coined. It’s actually about 500 years old according to Wikipedia.