What is the object of accompaniment (maf'ūl ma'ahu)?
A wāw does not always join two equals. Sometimes it means مَعَ — along with — and the ism after it is then the مَفْعُول مَعَهُ.
سِرْتُ وَالنِّيلَ (sirtu wa-al-nīla) — I walked alongside the Nile. The Nile did not walk. It is what the walking happened beside, so it takes nasab, not the rafa a partner in the action would take.
Five roles share the word مَفْعُول, and each answers a different question about the action: what it fell upon, how much of it there was, why it happened, who it happened alongside, and when or where.
Everything turns on what the wāw is doing. جَاءَ مُحَمَّدٌ وَعَلِيٌّ joins two doers, and عَلِيٌّ is marfū' by copying مُحَمَّدٌ. جَاءَ مُحَمَّدٌ وَالْجَيْشَ means Muhammad came along with the army — and الْجَيْشَ is manṣūb.
The wāw must follow a clause containing a verb, or an ism that carries a verb's meaning and its letters — an active participle, a passive participle, a maṣdar.
Do not confuse it with the مَعْطُوف — a word joined by an ordinary wāw.
A مَعْطُوف copies the i'rab of the word before it: جَاءَ مُحَمَّدٌ وَعَلِيٌّ — both marfū', both came.
A مَفْعُول مَعَهُ does not copy anything. It is manṣūb in its own right: جَاءَ مُحَمَّدٌ وَالْجَيْشَ — the army did not come, Muhammad came alongside it.
Read the wāw first, then the ending will make sense.