This question has been flagged


I have one model of the category with a child-parent relationship with itself.


class product_public_cate (models.Model):
    _name = "product.public.category"     parent_id = fields.Many2one ('product.public.category', 'parent category')


with many levels of child records, I want the main category and first child of the main category in the controller so fire a search method as below:

request.env ['product.public.category'].  search (['|', ('parent_id.parent_id', '=', False), ('parent_id', '=', False)], order = "parent_id desc")


It gives only the first child of the main category, not all main categories  

as I think there is some problem while comparing domain a parent_id.parent_id = false  
while there is no any parent_id.parent_id for main categories   

so wanted to know why this is happening ?  why I didn't get the main categories in the result is that a domain problem? 

thanks in advance.  



here are some queries that also I try but didn't get a result

request.env ['product.public.category']. search (['|', ('parent_id', '=', False), '&', ('parent_id', '! =', False), ('parent_id.parent_id', '=', False)] , order = "parent_id desc")


for 3 level child 
request.env ['product.public.category']. search (['!', ('parent_id.parent_id.parent_id', '=', False)])


Avatar
Discard