Community: Framework mailing list archives

Re: Enhancment proposal, new domain operator "parent_of"

Olivier Dony (odo)
- 05/12/2015 21:08:27
Hi Mohammad,

On Sat, May 9, 2015 at 12:12 PM, Mohammad Alhashash
<> wrote:
> I'd like to purpose a new operator "parent_of" with similar semantics to
> "child_of" operator but it would traverse parents instead of children.
> Here is an implementation based on master:
> If the concept is accepted, I'll add unit tests and documentation updates to
> make a pull request.

The concept is quite fine indeed, and to say the truth, I have had the
'parent_of' operator in my personal wish/todo list for several years
now :-)
So I would definitely welcome a proper PR with tests and documentation
against the master branch.

I haven't thoroughly checked your implementation yet, but as an
initial remark I would find it logical that 'parent_of' mirrors the
use cases of 'child_of'. This means that it should support all models
with a `parent_id` or `_parent_name` column, with or without
`_parent_store` (parent_left/right).
For those without `_parent_store`, a WITH RECURSIVE implementation is
good, but for those with `_parent_store` set, a single query with
parent_left/parent_right is better/faster. A simple domain
[('parent_left', '=',
n.parent_right)] should give you all ancestors of node `n` (including
the `n` itself).

Thanks for your excellent work!