  Context. One of the most fundamental scaling relations in galaxies is
observed between metallicity and stellar mass -- the mass-metallicity relation
(MZR) -- although recently a stronger dependence of the gas-phase metallicity
with the galactic gravitational potential ($\Phi \rm ZR$) has been reported.
Further dependences of metallicity on other galaxy properties have been
revealed, with the star formation rate (SFR) being one of the most studied and
debated secondary parameters in the relation (the so-called fundamental
metallicity relation). Aims. In this work we explore the dependence of the
gas-phase metallicity residuals from the MZR and $\Phi \rm ZR$ on different
galaxy properties in the search for the most fundamental scaling relation in
galaxies. Methods. We applied a random forest regressor algorithm on a sample
of 3430 nearby star-forming galaxies from the SDSS-IV MaNGA survey. Using this
technique, we explored the effect of 147 additional parameters on the global
oxygen abundance residuals obtained after subtracting the MZR. Alternatively,
we followed a similar approach with the metallicity residuals from the $\Phi
\rm ZR$. Results. The stellar metallicity of the galaxy is revealed as the
secondary parameter in both the MZR and the $\Phi \rm ZR$, ahead of the SFR.
This parameter reduces the scatter in the relations $\sim 10-15\%$. We find the
3D relation between gravitational potential, gas metallicity, and stellar
metallicity to be the most fundamental metallicity relation observed in
galaxies.
