Some crops, for example alliums like onions and garlic, prevent pests from attacking others by the smell that they emit.
Companion planting is an organic method of protecting crops from pests and diseases, by the simple process of planting beneficial crops near each other. Some crops, for example alliums like onions and garlic, prevent pests from attacking others by the smell that they emit. So using them for carrot companion planting, for example, means the smell of the onions will deter carrot fly.