111 # relation even with '1?' cardinality if thoses relations are added in the |
111 # relation even with '1?' cardinality if thoses relations are added in the |
112 # same transaction where the entity is being created. This never occurs from |
112 # same transaction where the entity is being created. This never occurs from |
113 # the web interface but may occurs during test or dbapi connection (though |
113 # the web interface but may occurs during test or dbapi connection (though |
114 # not expected for this). So: don't do it, we pretend to ensure repository |
114 # not expected for this). So: don't do it, we pretend to ensure repository |
115 # consistency. |
115 # consistency. |
|
116 # |
|
117 # also, we must not use unsafe_execute since we want the delete permission |
|
118 # to be checked when some existing relation is deleted |
116 if card[0] in '1?': |
119 if card[0] in '1?': |
117 rschema = session.repo.schema.rschema(rtype) |
120 rschema = session.repo.schema.rschema(rtype) |
118 if not rschema.inlined: # inlined relations will be implicitly deleted |
121 if not rschema.inlined: # inlined relations will be implicitly deleted |
119 session.unsafe_execute('DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype, |
122 session.execute('DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype, |
120 {'x': eidfrom, 'y': eidto}, 'x') |
123 {'x': eidfrom, 'y': eidto}, 'x') |
121 if card[1] in '1?': |
124 if card[1] in '1?': |
122 session.unsafe_execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype, |
125 session.execute('DELETE X %s Y WHERE NOT X eid %%(x)s, Y eid %%(y)s' % rtype, |
123 {'x': eidfrom, 'y': eidto}, 'y') |
126 {'x': eidfrom, 'y': eidto}, 'y') |
124 |
127 |
125 |
128 |
126 class Repository(object): |
129 class Repository(object): |
127 """a repository provides access to a set of persistent storages for |
130 """a repository provides access to a set of persistent storages for |
128 entities and relations |
131 entities and relations |