def test_fl_many_many_are_included_from_f_side_with_sort(self):
     singer1 = LinkedSinger(name='Teh Khim Leng')
     singer2 = LinkedSinger(name='M Teh Khim Leng')
     song1 = LinkedSong(name='Lu Bo To Teo Yeo', singers=[singer1,
                                                          singer2]).save()
     song2 = LinkedSong(name='Lw Bo To Teo Yeo', singers=[singer1,
                                                          singer2]).save()
     song3 = LinkedSong(name='Li Bo To Teo Yeo', singers=[singer1,
                                                          singer2]).save()
     song4 = LinkedSong(name='Teo Sua Si Gueh Hai',
                        singers=[singer1, singer2]).save()
     song5 = LinkedSong(name='Siao Thiang Go', singers=[singer1]).save()
     result = LinkedSinger.id(singer2.id).include(
         'songs',
         LinkedSong.find(name={
             '_prefix': 'L'
         }).order('name', -1)).exec()
     self.assertEqual(len(result.songs), 3)
     self.assertEqual(
         [song.name for song in result.songs],
         ['Lw Bo To Teo Yeo', 'Lu Bo To Teo Yeo', 'Li Bo To Teo Yeo'])
     result = LinkedSinger.id(singer2.id).include(
         'songs',
         LinkedSong.find(name={
             '_prefix': 'L'
         }).order('name', 1)).exec()
     self.assertEqual(len(result.songs), 3)
     self.assertEqual(
         [song.name for song in result.songs],
         ['Li Bo To Teo Yeo', 'Lu Bo To Teo Yeo', 'Lw Bo To Teo Yeo'])
 def test_fl_many_many_are_included_from_f_side_with_filter(self):
     singer1 = LinkedSinger(name='Teh Khim Leng')
     singer2 = LinkedSinger(name='M Teh Khim Leng')
     song1 = LinkedSong(name='Lu Bo To Teo Yeo', singers=[singer1,
                                                          singer2]).save()
     song2 = LinkedSong(name='Teo Sua Si Gueh Hai',
                        singers=[singer1, singer2]).save()
     song3 = LinkedSong(name='Siao Thiang Go', singers=[singer1]).save()
     result = LinkedSinger.id(singer2.id).include(
         'songs', LinkedSong.find(name={'_prefix': 'L'})).exec()
     self.assertEqual(len(result.songs), 1)
     self.assertEqual(result.songs[0].id, song1.id)