The story
From a Greek fable about a dog preventing other animals from eating the hay in a manger, even though as a carnivore it could not eat the hay itself. Although the story was ascribed to Aesop's Fables in the 15th century, no ancient source does so. The phrase first appears in the writings of Diogenianus.
Etymology from Wiktionary, CC BY-SA 4.0.