In the context of SQLObject, the rationale behind such a requirement as class attribute collection is simple. The SQLObject base classes are not always going to know which parameters are used with the class. When instantiating SQLObject instances, the keyword parameters correlate to the fields declared for that instances' database table. In several scenarios, SQLObject needs to inspect a given class and return a list of attributes that were passed to the constructor. This list of parameters at this point are unknown to the class, although, the SQLObject attribute collection functionality assumes that this each attribute in this list is a class attribute of the class being inspected. Since much of the behavior invoked on SQLObject instances is transformed, and called by meta classes, the attributes may not necessarily be needed by the instance. The attribute collection functionality in SQLObject has an opportunity to remove these attributes from the instance and perform any other transformations it sees fit. It also accepts parameters to help it determine what exactly it is modifying.
The _collectAttributes() function is where this functionality is implemented. The parameters that can be passed to this function are as follows.
- cls - This is the actual class that is being inspected. It is assumed that all attributes being collected are a part of this class.
- new_attrs - This parameter is the dictionary of keyword parameters that are passed to the constructor of SQLObject instances. The values in this dictionary are SQLObject column types.
- look_for_class - The column type to look for. Only attributes of this type will be returned.
- delete - If true, all attributes will be deleted from the class.
- set_name - The actual attribute name will change to the key of the dictionary item corresponding to the attribute.
- sort - If true, a sorted list will be returned. The sorting is based on field creation order.
No comments :
Post a Comment