while the rainbow bean raises the affection to 3 hearts, this is still imprecise.
To be more precise, the rainbow bean gives around 125 affection points. On serebii they say you just need 3 beans to bring it to max affection the third one is actually a waste.
I had a dhelmise that only had 4 affection points (by healing a status right after battling with the cotton thing. I feed it two rainbow beans, and then petted it once. After said petting it displayed the animation telling that the affection was maxed.
So yeah, you only need two beans and some petting.
Also, I found that is way better to keep the pattern beans for boosting berries and such than actual trading. Using just regular beans you can boost as much as 16h40m before needing to put more beans. for berries that only takes 24h to grow is okay, as you would only need to put beans for 12h, but for the other beans you would need to refresh it, and if you're not avaiable when the beans run out you would be losing efficiency.
But with the pattern beans, you can put 11 pattern beans and 39 regular beans for 24h of boosting for the berries that take 48h to grow, and 29 pattern beans plus 21 regular beans for the berries that take 72 hours to grow. The berries will finish as the bean boost will end.
For the rainbow beans, the best use is pokemon refresh, and for trading if you have too many of them and for some reason you need more regular beans. Once you have everything built to lv3 and you have more beans that you can use you could use these for boosting if you want.
Also, anyone has a table of the chances of getting X item in treasure hunt?