But Worf wasn't second officer, Data was. Of course Data was Lt cmdr so Troi out ranked him. Yet Data was still second officer.
However, look at Christine Vale who Riker got promoted because Vale didn't want to be lower in rank than Troi.
Funny how much discussion rank is generating.