"cut a 2x4 to fit snug between the joists and drive 2 log screws into each side.then screw the electrical box to it from below. easypeasyjapaneesy "
Yeah, that's easy if you don't mind ripping apart the ceiling to do it. I assumed the OP could easily figure out how to do it, with the ceiling open. I think the question was how to do it with just an opening the size of an electrical box.