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

Class many2many

source code

    object --+                
             |                
      property --+            
                 |            
datatypes.datatype --+        
                     |        
          relationship --+    
                         |    
                    _2many --+
                             |
                            many2many

The many to many relationship manages rows from two tables which are linked by means of a third table, the link_relation. This tables stores keys from each of the tables that are to be linked. Note that these keys must be single column keys.

If you set a many2many property to a list of child objects or append one it will be inserted into the databse if need be.

The result class implements a subset of the list interface, but the lists elements are considered to have no guaranteed order (as the values in a dict have no order).

Nested Classes [hide private]
  result
Instances of this class are returned if you __get__ a many2many dbproperty.

Instance Methods [hide private]
  __init__(self, child_class, link_relation, parent_own_key=None, parent_link_column=None, child_own_key=None, child_link_column=None, title=None)
  __set__(self, dbobj, value)
Set the attribute managed by this datatype class on instance to value.
  parent_own_key(self, dbobj)
  parent_link_column(self, dbobj)
  child_own_key(self)
  child_link_column(self)

Inherited from _2many: __get__, __init_dbclass__

Inherited from relationship: __convert__, __select_after_insert__, __select_this_column__, __set_from_result__, isset, sql_literal

Inherited from datatypes.datatype: __delete__, __setattr__, add_widget, check_dbobj, data_attribute_name, widget_specs

Inherited from property: __getattribute__, __new__

Inherited from object: __delattr__, __hash__, __reduce__, __reduce_ex__, __repr__, __str__


Class Methods [hide private]
  reverse(cls, original_dbclass, attribute_name, title=None)
Constructor.

Class Variables [hide private]

Inherited from datatypes.datatype: python_class, sql_literal_class

Inherited from property: fdel, fget, fset


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, child_class, link_relation, parent_own_key=None, parent_link_column=None, child_own_key=None, child_link_column=None, title=None)
(Constructor)

source code 
Parameters:
  • parent_own_key - The attribute in the parent dbclass that is referred to by the link table. Defaults to the primary key.
  • parent_link_column - The column name(!) in the link table referring to parent_own_key. Defaults to <parent class name>_<primary key column>.
  • child_own_key - The attribute in the child dbclass that is referred to by the link table. Defaults to the primary key.
  • child_link_column - The column name(!) in the link table referring to child_own_key. Defaults to <child class name>_<child key column>.
Overrides: relationship.__init__

__set__(self, dbobj, value)

source code 
Set the attribute managed by this datatype class on instance to value. This will be called by Python on attribute assignment. The __set_from_result__ method does the same thing for data retrieved from the RDBMS. See below.
Overrides: _2many.__set__

reverse(cls, original_dbclass, attribute_name, title=None)
Class Method

source code 

Constructor.

A little helper function: If you've defined one many2many relation, this constructor will take it as an argument and return the complimentary one to be an attribute in the child class.
Parameters:
  • original_dbclass - dbclass you've already defined a many2many relationship for.
  • attribute_name - Attribute name of the many2many relationship in the original dbclass.

parent_own_key(self, dbobj)

source code 
None

parent_link_column(self, dbobj)

source code 
None

child_own_key(self)

source code 
None

child_link_column(self)

source code 
None