Package orm2 :: Module relationships :: Class many2many :: Class result
[hide private]
[frames] | no frames]

Class result

source code

   object --+    
            |    
_2many.result --+
                |
               many2many.result

Instances of this class are returned if you __get__ a many2many dbproperty.

Instance Methods [hide private]
  select(self, *clauses)
Use like this:
  len(self, *clauses)
Return the number of child objects associated with a parent.
  where(self)
Return the WHERE clause that selects the child objects for the given parent.
  all(self, *clauses)
This method will return all entries in the child relation (or a subset specified by clauses) and a list of those primary keys which are present in the link table.
  append(self, *new_child_objects)
Appends new child objects to the parent's many2many dbproperty.
  unlink(self, child_object)
Remove the entry from the link relation that links it to the parent dbobj.
  unlink_by_primary_key(self, pkey)
Remove an entry from the link relation that links the parent dbobj to a child identfyed by pkey

Inherited from _2many.result: __getattr__, __init__, __iter__, __len__, add_where, child_class, ds

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

select(self, *clauses)

source code 
Use like this:
>>> result = dbobj.children.select(sql.where(...))
This will yield those child objects that fit the condition in the where statements. Note that your WHERE will be integrated into a more complex WHERE clause. The many2many relationship uses a LEFT JOIN to connect the link_relation and the child relation. You must do that by hand. Also, doing so might mess up your db, so you might want to use FOREIGN KEY constraints on the link relation.
Overrides: _2many.result.select

len(self, *clauses)

source code 
Return the number of child objects associated with a parent. You may supply a where clause. The same things apply as for the where clause for select(), see above.
Overrides: _2many.result.len

where(self)

source code 
Return the WHERE clause that selects the child objects for the given parent. The clause will also include the condition to limit the JOIN to the appropriate rows.
Overrides: _2many.result.where

all(self, *clauses)

source code 
This method will return all entries in the child relation (or a subset specified by clauses) and a list of those primary keys which are present in the link table. You can check if a dbobj is linked by doing:
>>> result, active_keys = dbobj.relation.all()
>>> for a in result:
...     if a.__primary_key__.values() in active_keys:
...         do_something(a)
...     else:
...         do_somethin_else(a)

append(self, *new_child_objects)

source code 
Appends new child objects to the parent's many2many dbproperty.
Overrides: _2many.result.append

unlink(self, child_object)

source code 
Remove the entry from the link relation that links it to the parent dbobj.

unlink_by_primary_key(self, pkey)

source code 
Remove an entry from the link relation that links the parent dbobj to a child identfyed by pkey
Parameters:
  • pkey - An sql.literal instance