These plants have legumes or small spaces in their roots where a special kind of bacteria live. These Bacteria are called nitrogen-fixing bacteria. Plants need nitrogen to make amino acids which make proteins which make the cells which is important for growth, but plants cannot use the nitrogen in the air(they are unable to). So they absorb nitrate ions(NO3) from the soil as a source of nitrogen. If you read about the nitrogen cycle(a very simple concept) you will realise there is nitrogen fixing bacteria present in the soil. These bacteria 'breathe' in nitrogen and uses energy to transform the nitrogen to a nitrate ion.
Leguminous plants take the nitrate ions directly from these nitrogen-fixing bacteria as in the case of leguminous plants these bacteria live in the roots of the plants. Farmers use these plants(such as peas) to provide nitrate ions to soil that may be deficient(lack of) in nitrate ions as these plants produce the nitrate ions in excess