Interplay of magnetic and structural transitions in iron-based pnictide superconductors