This problem fixes the issue, unfortunately I don't have much time to work on this and breakpoint wouldn't function inside of that file. I am unsure if @owner is the correct instance variable to interpolate with in all instances and unsure if all instances should be interpolated (but a casual look suggests they should).
This didn't affect any current unit tests (run under the sqlite3 store), and it does fix the issue, but needs someone who better knows how this file works to check that each place interpolate_sql is called is correct.
NOTE: If you made this file and don't understand why you can't just interpolate it once - we can't put #{id} in there and have it interpolated if you interpolate once and then cache the result as it will always be the ID of the first record that accessed the relationship, which is broken.