If you have ever finished https://www.railstutorial.org/ deals with relationshps rather well. Can’t send code.
Cheers Dave