211 |
211 |
212 without read security check but also all the burden of rql execution. |
212 without read security check but also all the burden of rql execution. |
213 You may use this in hooks when you know both eids of the relation you |
213 You may use this in hooks when you know both eids of the relation you |
214 want to add. |
214 want to add. |
215 """ |
215 """ |
|
216 self.add_relations([(rtype, [(fromeid, toeid)])]) |
|
217 |
|
218 def add_relations(self, relations): |
|
219 '''set many relation using a shortcut similar to the one in add_relation |
|
220 |
|
221 relations is a list of 2-uples, the first element of each |
|
222 2-uple is the rtype, and the second is a list of (fromeid, |
|
223 toeid) tuples |
|
224 ''' |
|
225 edited_entities = {} |
|
226 relations_dict = {} |
216 with security_enabled(self, False, False): |
227 with security_enabled(self, False, False): |
217 if self.vreg.schema[rtype].inlined: |
228 for rtype, eids in relations: |
218 entity = self.entity_from_eid(fromeid) |
229 if self.vreg.schema[rtype].inlined: |
219 edited = EditedEntity(entity) |
230 for fromeid, toeid in eids: |
220 edited.edited_attribute(rtype, toeid) |
231 if fromeid not in edited_entities: |
|
232 entity = self.entity_from_eid(fromeid) |
|
233 edited = EditedEntity(entity) |
|
234 edited_entities[fromeid] = edited |
|
235 else: |
|
236 edited = edited_entities[fromeid] |
|
237 edited.edited_attribute(rtype, toeid) |
|
238 else: |
|
239 relations_dict[rtype] = eids |
|
240 self.repo.glob_add_relations(self, relations_dict) |
|
241 for edited in edited_entities.itervalues(): |
221 self.repo.glob_update_entity(self, edited) |
242 self.repo.glob_update_entity(self, edited) |
222 else: |
243 |
223 self.repo.glob_add_relation(self, fromeid, rtype, toeid) |
|
224 |
244 |
225 def delete_relation(self, fromeid, rtype, toeid): |
245 def delete_relation(self, fromeid, rtype, toeid): |
226 """provide direct access to the repository method to delete a relation. |
246 """provide direct access to the repository method to delete a relation. |
227 |
247 |
228 This is equivalent to the following rql query: |
248 This is equivalent to the following rql query: |