Home | Trees | Indices | Help |
|
---|
|
object --+ | property --+ | datatypes.datatype --+ | _container --+ | sqldict
This datatype represents a relationship between relations in which the child relation proveies a number of values for a parent relation indexed by the parent's primary key and a unique key for each of the entries. In the parent dbobject these key/value pairs appear as a dict. Like this: CREATE user ( id INTEGER, ... some more fields ... ); CREATE user_info ( user_id INTEGER REFERENCES user(id), key VARCHAR(100), value TEXT, PRIMARY KEY(user_id, key) ); The PRIMARY KEY clause is not strictly necessary, but it will make sure every user_id/key pair only appears once. You may also want to create an index over the user_id column, because queries will usually call for all the child rows associated with the parent. An appropriate dbclass would look like this:: class user(dbobject): id = integer() info = sqldict('user_info', varchar(column=key), Unicode(column=value)) result = ds.select(user) me = result.next() me.info['firstname'] = 'Diedrich' me.info['lastname'] = 'Vorberg' if me.info['age'] > 30: print 'Consider suicide!' As for the sqltuple the whole thing only works on single-column primary keys.
|
|||
| sqldict_dict |
|
|||
|
__init__(self,
child_relation,
child_key_column,
child_value_column,
child_key=None,
title=None) @param child_relation: sql.relation object or string, indicating the name of the dependent relation. |
||
| __init_dbclass__(self, dbclass, attribute_name) | ||
|
__get__(self,
dbobj,
owner="Who??") See the Python Language Reference, chapter 3.3.2.2 for details on how this works. |
||
|
__set__(self,
dbobj,
new_dict) Set the attribute managed by this datatype class on instance to value. |
||
Inherited from Inherited from Inherited from Inherited from |
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
@param child_relation: sql.relation object or string, indicating the name of the dependent relation. @param child_column: It's datatype (datatype object). The datatype's column parameter may be used as well as teh validators. Title and has_default will be ignored. The column name defaults to the container's attribute_name in the parent dbclass. @param child_key: A string indicating the column in the child relation that is used in the foreign key to point to the parent. The the docstrings of the actual implementations for examples, that's going to make it clearer. As a sidenote: This only works for a single-column reference key from the parent class to the child class. It would be possible implementing this for multiple column keys using an anonymous dbclass, but it's just soooo darn complicated! So I thought to myself that orm2 is complecated enough...
|
|
|
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0alpha3 on Wed Feb 20 18:17:24 2008 | http://epydoc.sourceforge.net |