Reconciling Donald Trump’s self-promoting “Art of the Deal” with the military’s reserved code of loyalty and service was always a stretch. In Trump’s early months in the White House, though, the two cultures seemed to coexist without much damage.

But the fabric began to fray by mid-2017. Trump increasingly treated the military as props in the reality-TV show of his presidency. He wanted them for parades and victory celebrations, not the anguish of combat. He seemed to take his strategic guidance from Fox News more than his commanders. The generals and admirals kept their mouths shut, but the resentment was building.

The bad marriage exploded this week, when former senior staff members told Jeffrey Goldberg of the Atlantic of their shock at Trump’s crude comments about combat and loss – and his reported characterization of fallen warriors as “suckers” and “losers.” The quotes were anonymous, but it has been an open secret in Washington that many prominent retired four-stars have regarded Trump with growing horror as he assaulted the traditions of discipline and professionalism that are bedrocks of military life.

The first open break point came in June, after former military leaders watched Trump try to use the military to put down protests for racial justice. Retired Adm. Mike Mullen, former chairman of the Joint Chiefs of Staff, denounced Trump for “politicizing the men and women of our armed forces.” Retired Gen. Jim Mattis, the former defense secretary, called Trump “the first president in my lifetime who does not try to unite the American people.” Retired Gen. John F. Kelly, a former Trump White House chief of staff, said he agreed with Mattis.

It’s hard to remember now that Trump’s dealings with military leaders started off pretty well. I remember traveling in May 2017 with our Special Operations forces to the newly liberated town of Tabqa, at the gates of the Islamic State’s capital of Raqqa. A senior U.S. official told the Syrian Kurdish commander who led the assault that this rapid assault “never would have happened without Donald Trump.” There would have been too many meetings under his predecessor, President Barack Obama.

Trump wanted victory in Afghanistan, too, so long as it was fast and unambiguous. Gen. John Nicholson, the U.S. commander in Kabul, was given authority to use America’s most intimidating conventional weapon against the Taliban – the so-called “mother of all bombs.” No more anguished meetings in the Situation Room. The gloves were off.

Trump initially saw Mattis as a man in his own image – awarding him the Trumpian nickname “Mad Dog,” even though the ascetic Mattis was closer to a monk than a mongrel. Over the two years Mattis ran the Pentagon, his relationship with Trump grew poisonous. The more Mattis tried to educate Trump, as in his widely reported July 2017 seminar in the “tank” at Pentagon, the more Trump became resentful.

Trump berated his generals at that gathering – with language that’s eerily similar to what was reported in the Atlantic this week. According to Philip Rucker and Carol D. Leonnig in their book, “A Very Stable Genius,” Trump said: “You’re all losers. You don’t know how to win anymore.”

Trump really did seem to think he knew better than his generals. “I wouldn’t go to war with you people,” Trump told them, according to Rucker and Leonnig. “You’re a bunch of dopes and babies.”

The commander who succeeded best in keeping the lid on, as Trump grew cockier, was Gen. Joseph F. Dunford Jr., the chairman of the Joint Chiefs. A tall, reserved and utterly reliable Marine, he was often able to curb Trump’s impulsive decisions and steer him toward steady policy, without infuriating him.

What the military liked in Trump was that he was sometimes (not always) prepared to “take the shot” at terrorist adversaries, such as Abu Bakr al-Baghdadi, the leader of the Islamic State, and Gen. Qasem Soleimani, the leader of Iran’s Quds Force.

Trump’s near-constant belittling of NATO hurt his standing with the Pentagon. So did his inexplicable affinity for Russian President Vladimir Putin. Yet military leaders bit their lips, because they were grateful that Trump had endorsed a national military strategy that took a tougher stance toward Russia and China – and added money for new weapons to combat these near-peer adversaries.

A heartbreaker for the military was Trump’s decision to abandon the Syrian Kurds who had fought so bravely against the Islamic State. I remember talking to the officer who had to break the news of Trump’s decision to quit Syria to Gen. Mazloum Abdi, the commander of the Syrian Democratic Forces. His description of that betrayal was unprintable.

What the military came to understand over the past four years is that, for all Trump’s talk of patriotism, he truly is transactional. Throughout his career, he has always believed that loyalty was for chumps. That’s why New York business executives told me back in early 2016 they had never wanted to do business with him.

The military understand their role in a democracy. They have obeyed Trump as their commander in chief, even amid his tirades and insults. And they will continue to do so if he’s reelected. But many of them won’t like it: Trump just isn’t a guy with whom you’d want to share a foxhole.

Contact David Ignatius on Twitter @IgnatiusPost.