During the Middle Ages, the kingdom of Galicia was occasionally ruled by its own kings, but most of the time it was leagued to the kingdom of Leon and later to that of Castile, while maintaining its own legal and customary practices and personality.