fixed several issues with active record relations