Changeset 383
- Timestamp:
- 08/04/08 10:52:41 (4 years ago)
- Location:
- elixir/trunk
- Files:
-
- 5 modified
-
CHANGES (modified) (1 diff)
-
elixir/__init__.py (modified) (2 diffs)
-
elixir/fields.py (modified) (5 diffs)
-
elixir/properties.py (modified) (1 diff)
-
tests/test_fields.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/CHANGES
r382 r383 9 9 underlying constructs 10 10 11 Changes: 12 - removed support for the deprecated with_fields syntax 11 13 12 14 0.6.0 - 2008-07-18 -
elixir/trunk/elixir/__init__.py
r377 r383 33 33 from elixir.entity import Entity, EntityMeta, EntityDescriptor, \ 34 34 setup_entities, cleanup_entities 35 from elixir.fields import has_field, with_fields,Field35 from elixir.fields import has_field, Field 36 36 from elixir.relationships import belongs_to, has_one, has_many, \ 37 37 has_and_belongs_to_many, \ … … 45 45 46 46 __all__ = ['Entity', 'EntityMeta', 'EntityCollection', 'entities', 47 'Field', 'has_field', 'with_fields',47 'Field', 'has_field', 48 48 'has_property', 'GenericProperty', 'ColumnProperty', 'Synonym', 49 49 'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many', -
elixir/trunk/elixir/fields.py
r370 r383 3 3 entities. Elixir currently supports two syntaxes to do so: the default 4 4 `Attribute-based syntax`_ as well as the has_field_ DSL statement. 5 6 Note that the old with_fields_ statement is currently deprecated in favor of7 the `Attribute-based syntax`_.8 5 9 6 Attribute-based syntax … … 107 104 has_field('id', Integer, primary_key=True) 108 105 has_field('name', String(50)) 109 110 111 with_fields112 -----------113 The `with_fields` statement is **deprecated** in favor of the `attribute-based114 syntax`_.115 116 It allows you to define all fields of an entity at once.117 Each keyword argument to this statement represents one field, which should118 be a `Field` object. The first argument to a Field object is its type.119 Following it, any number of keyword arguments can be specified for120 additional behavior. The `with_fields` statement supports the same keyword121 arguments than the `has_field` statement.122 123 Here is a quick example of how to use ``with_fields``.124 125 .. sourcecode:: python126 127 class Person(Entity):128 with_fields(129 id = Field(Integer, primary_key=True),130 name = Field(String(50))131 )132 106 ''' 133 107 import sys … … 148 122 149 123 This class represents a column on the table where the entity is stored. 150 This object is only used with the `with_fields` syntax for defining all151 fields for an entity at the same time. The `has_field` syntax does not152 require the manual creation of this object.153 124 ''' 154 125 … … 197 168 self.property = deferred(self.column, group=group) 198 169 elif self.name != self.colname: 199 # if the property name is different from the column name, we need 170 # if the property name is different from the column name, we need 200 171 # to add an explicit property (otherwise nothing is needed as it's 201 172 # done automatically by SA) … … 219 190 field.attach(entity, name) 220 191 221 222 def with_fields_handler(entity, *args, **fields):223 for name, field in fields.iteritems():224 field.attach(entity, name)225 226 227 192 has_field = ClassMutator(has_field_handler) 228 with_fields = ClassMutator(with_fields_handler) -
elixir/trunk/elixir/properties.py
r382 r383 154 154 super(GenericProperty, self).__init__(*args, **kwargs) 155 155 self.prop = prop 156 #XXX: move this to Property? 156 157 self.args = args 157 158 self.kwargs = kwargs -
elixir/trunk/tests/test_fields.py
r349 r383 45 45 46 46 assert p.surname == 'Simpson' 47 48 def test_with_fields(self):49 class Person(Entity):50 with_fields(51 firstname = Field(String(30)),52 surname = Field(String(30))53 )54 55 setup_all(True)56 57 homer = Person(firstname="Homer", surname="Simpson")58 bart = Person(firstname="Bart", surname="Simpson")59 60 session.commit()61 session.clear()62 63 p = Person.get_by(firstname="Homer")64 65 assert p.surname == 'Simpson'66
