def test_fl_many_many_are_included_from_l_side_with_sort_and_sort_will_not_work( self): singer1 = LinkedSinger(name='AQ') singer2 = LinkedSinger(name='BQ') singer3 = LinkedSinger(name='CC') singer4 = LinkedSinger(name='DD') song1 = LinkedSong(name='Lu Bo To Teo Yeo', singers=[singer2, singer1, singer3, singer4]).save() LinkedSong(name='Teo Sua Nang To Cim Tsung Ci', singers=[singer3, singer4]).save() result = LinkedSong.one(name='Lu Bo To Teo Yeo').include( 'singers', LinkedSinger.find(name={ '_suffix': 'Q' }).order('name', -1)).exec() self.assertEqual(len(result.singers), 2) self.assertEqual([singer.name for singer in result.singers], ['BQ', 'AQ']) result = LinkedSong.one(name='Lu Bo To Teo Yeo').include( 'singers', LinkedSinger.find(name={ '_suffix': 'Q' }).order('name', 1)).exec() self.assertEqual([singer.name for singer in result.singers], ['BQ', 'AQ']) self.assertEqual(len(result.singers), 2)
def test_fl_many_many_are_included_from_l_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() singer3 = LinkedSinger(name='Phua Kheng Lim') singer4 = LinkedSinger(name='M Phua Kheng Lim') LinkedSong(name='Teo Sua Nang To Cim Tsung Ci', singers=[singer3, singer4]).save() result = LinkedSong.one(name='Lu Bo To Teo Yeo').include( 'singers', LinkedSinger.find(name={'_prefix': 'M'})).exec() self.assertEqual(len(result.singers), 1) self.assertEqual(result.singers[0].id, singer2.id)