This question has been flagged
1 Reply
6130 Views

I want to apply the len(one2many_field) in Search method of ORM. Like this search(..,order = "len(one2many_field)",..) .I want to order the result by finding total number of their children. The one2many field is in the relation to the same table. Presently I am not able to use len() in order.

Example :

 id    name    parent_id
  1     A       - 
  2     B       1 
  3     C       1 
  4     D       - 
  5     E       4

Result :

A
D
Avatar
Discard
Best Answer

In order parameter you can only pass fields name. Search method sorts the ids based on your given field and returns them. You cannot give numbers in order parameter.

In limit=50 you can use numbers.

Avatar
Discard
Author

Okay. Then what are the other ways to arrange then by their length of children. You can see what I want to do in the above example. Thanking you.