Reference for Bava Metzia 8:1
הַשּׁוֹאֵל אֶת הַפָּרָה וְשָׁאַל בְּעָלֶיהָ עִמָּהּ אוֹ שָׂכַר בְּעָלֶיהָ עִמָּה. שָׁאַל הַבְּעָלִים אוֹ שְׂכָרָן, וּלְאַחַר כָּךְ שָׁאַל אֶת הַפָּרָה, וָמֵתָה, פָּטוּר, שֶׁנֶּאֱמַר (שמות כב) אִם בְּעָלָיו עִמּוֹ לֹא יְשַׁלֵּם. אֲבָל שָׁאַל אֶת הַפָּרָה וְאַחַר כָּךְ שָׁאַל אֶת הַבְּעָלִים אוֹ שְׂכָרָן, וָמֵתָה, חַיָּב, שֶׁנֶּאֱמַר (שם) בְּעָלָיו אֵין עִמּוֹ שַׁלֵּם יְשַׁלֵּם:
If one borrowed a cow and borrowed its owner with it, [i.e., If the owner of the cow were with the borrower to do his work — whether he were borrowed or hired by him; whether to work with the cow or to do some other work]; or if he borrowed or hired the owner and then borrowed the cow, and it died, he is not liable, it being written (Exodus 22:14): "If its owner were with him, he shall not pay" [the implication being: If the owner of the ox were with him, with the borrower, being lent to or hired by him to do his work, at the time he lent him his cow, he shall not pay.] But if he borrowed the cow and then borrowed or hired the owner, and it died, he is liable, it being written (Exodus 22:13): "If its owner were not with him, pay shall he pay." [If he (the owner of the animal) were with him (the borrower) at the time of the accident, but not at the time of the borrowing, he (the borrower) is liable, it not being "borrowing with the owner" to exempt him unless he were with him at the time of the borrowing. The verse is to be understood as follows: "If its owner were not with him (the borrower)" at the time of the borrowing, even if he were with him at the time of breaking or death, "pay shall he pay."]