def __init__(self, child_class, child_key=None, foreign_key=None, column=None, title=None, has_default=None, cache=True): """ @param cache: Indicates whether the relationship object shall keep a copy of the child object in the dbobj for faster access. """ if foreign_key is not None and column is not None: raise Exception("You can't specify both a foreign_key (based"+\ " on attribute names) and an SQL column for "+\ " a many2one relationship") datatype.__init__(self, column, title, (), has_default) if foreign_key is None: pk = keys.primary_key(child_class) self.python_class = pk.attribute().python_class self.sql_literal_class = pk.attribute().sql_literal_class self.child_class = child_class if child_key is None: self.child_key = child_class.__primary_key__ else: self.child_key = child_key self.foreign_key = foreign_key self.cache = cache
def __init__(self, child_relation, child_column, child_key=None, title=None): """ @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 t4.orm is complecated enough... """ datatype.__init__(self, None, title) self.child_relation = child_relation self.child_column = child_column self.child_key = child_key
def __init__(self, child_class, child_key=None, foreign_key=None, title=None, has_default=None): """ @param child_class: The dbclass, this property's owner has a relationship to @param child_key: A string or a tuple of strings indicating those properties of the child_class that are used in the foreign key. This defaults to the child's primary key. The child_key must match the foreign_key in the number of its members and the attribute's datatypes. @param foreign_key: The foreign key. Simmlar to a dbclass' primary key this may be a simple string, indication the attribute that manages the foreign key column or a tuple of strings indicating columns that form the foreign key together. If the foreign key parameter is None __init_dbclass__() will try to guess the foreign key name as 'child's table'_'primary key column'. """ datatype.__init__(self, column=None, title=title, validators=(), has_default=has_default) self.child_class = child_class self.child_key = child_key self.foreign_key = foreign_key