author Sylvain Thénault <>
Mon, 11 Dec 2017 16:10:27 +0100
changeset 2906 69ce3f55cd88
parent 2862 f434324b01f0
child 2933 95b23f96c77b
permissions -rw-r--r--
[seda tree] Extract reparenting into a generic function and move it to the itree module since this is entity logic, not view.

# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact --
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <>.

from logilab.common.decorators import monkeypatch

from cubicweb.entity import Entity
from cubicweb.rqlrewrite import RQLRelationRewriter
from cubicweb.server import ssplanner

Entity.cw_skip_copy_for.append(('container', 'subject'))
Entity.cw_skip_copy_for.append(('container', 'object'))
Entity.cw_skip_copy_for.append(('clone_of', 'subject'))
Entity.cw_skip_copy_for.append(('clone_of', 'object'))

# monkey-patch to allow using computed relation in WHERE clause of write queries
# (

def _select_plan(self, plan, select, solutions):
    union = ssplanner.Union()
    ssplanner.add_types_restriction(self.schema, select)
    rewriter = RQLRelationRewriter(plan.cnx)
    rewriter.rewrite(union, plan.args)
    return self.build_select_plan(plan, union)