ספר המדות Improper Thoughts / Part I · לט
Sefer HaMiddot 770
לט. כְּשֶׁאִישׁ אוֹ אִשָּׁה חוֹשְׁבִים בִּשְׁעַת תַּשְׁמִישׁ בְּאֵיזֶה גּוֹי אוֹ בְּגוֹיָה, וְהַמַּחֲשָׁבָה הִיא בְּאַהֲבָה לְאֵיזֶה גּוֹי אוֹ גּוֹיָה, אֲזַי הַוָּלָד הַנּוֹלָד מִזֶּה הַתַּשְׁמִישׁ נִשְׁתַּמֵּד.
39. When a man or woman thinks at the time of marital relations about some non-Jewish man or woman, and the thought is with love for that non-Jewish man or woman, then the child who is born from these relations will abandon the Jewish faith.