The effect in question is caused by the high content of oligosaccharides--short sugar chain molecules--in beans. Humans lack the enzyme to digest these, and so they reach the large intestine intact, where resident bacteria eat them producing gas. Therefore, there are two ways to mitigate the effect:
- Remove the ogilosaccharides
- Provide the enzyme
This paper from the Pakistan Journal of Nutrition says, in regards to the Seker bean (a legume variety from Turkey), emphasis added, tells us the most effective way to remove the oligosaccharides:
The highest removing, to the extent of decrease up to, approximately,
70% was achieved by soaking in 0.5 % sodium bicarbonate solution for
18 hour followed by cooking in pressured kettle. These conditions
could be recommended to remove undesirable [oligosaccharide] contents of the Seker
bean used for culinary purposes.
The underlying science should be extremely analogous for any bean. Note the three techniques:
- Using a tiny amount of baking soda to decrease pH
- Long soaking (and then discarding the soaking liquid)
- Pressure cooking
However, they suggest that the consumer may wish to use simple plain water, and accept a higher level of flatus, because the above method will also further reduce the the availability of Vitamin B contents, especially thiamin and riboflavin.
Per The Accidental Scientist, you may also wish to (among their other suggestions):
Try an over-the-counter digestive aid, such as Beano, which contains
the sugar-digesting enzyme that the body lacks. Use Beano just before
eating so it can break down the gas-producing oligosaccharides. It has
no effect, however, on gas caused by lactose or fiber.