Farms were always placed as close to the city as much as possible, because it is impractical to transport food from a distance. An ox-drawn cart isn't faster than walking speed, so farmers still had to live a walkable distance from the city market.

Historic cities and castles are almost always wrongly depicted in movies. They are always placed in a grace field in the middle of nowhere, but there should be farmland everywhere.