Changeset 72
- Timestamp:
- 02/27/07 15:31:10 (6 years ago)
- Location:
- elixir/trunk
- Files:
-
- 4 modified
-
CHANGES (modified) (1 diff)
-
docs/download.rst (modified) (1 diff)
-
docs/index.rst (modified) (1 diff)
-
elixir/relationships.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/CHANGES
r71 r72 6 6 list that is neither threadsafe, nor safe when doing nested class 7 7 definition. Also added a test to validate that this works. 8 - fixed foreign key names on MySQL (and possibly other) databases by 9 making sure the generated name is unique for the whole database, and not 10 only for the table on which it applies. 8 11 - implemented singletable non-polymorphic inheritance 9 12 - added support to pass non-keyword arguments to tables. You just pass -
elixir/trunk/docs/download.rst
r59 r72 17 17 out how to use it (it's pretty easy, like the name promises). 18 18 19 20 Releases 21 -------- 22 23 Each release is also available for standard download on the `Cheese Shop 24 <http://cheeseshop.python.org/pypi/Elixir/>`_ 25 19 26 Development Version 20 27 ------------------- -
elixir/trunk/docs/index.rst
r49 r72 16 16 focuses on providing a simpler syntax for defining model objects when you do 17 17 not need the full expressiveness of SQLAlchemy's manual mapper definitions. 18 19 ------- 20 Example 21 ------- 22 23 Here is a very short model definition example, so that you can see what the 24 syntax look like. For some explanation and more complete examples, please have 25 a look at the `tutorial <tutorial.html>`_ or at the 26 `examples page <examples.html>`_. 27 28 :: 29 30 class Person(Entity): 31 has_field('name', Unicode(255)) 32 33 has_many('addresses', of_kind='Address') 34 35 36 class Address(Entity): 37 has_field('email', String(128)) 38 39 belongs_to('person', of_kind='Person') 40 18 41 19 42 ------- -
elixir/trunk/elixir/relationships.py
r70 r72 416 416 self.primaryjoin_clauses.append(field.column == pk_col) 417 417 418 # TODO: better constraint-naming? 418 # In some databases (at lease MySQL) the constraint name needs to 419 # be unique for the whole database, instead of per table. 420 fk_name = "%s_%s_fk" % (self.entity.table.name, self.name) 419 421 source_desc.add_constraint(ForeignKeyConstraint( 420 422 fk_colnames, fk_refcols, 421 name= self.name +'_fk',423 name=fk_name, 422 424 **self.constraint_kwargs)) 423 425 … … 514 516 % (self.entity.__name__, self.name) 515 517 ) 518 519 # We use the name of the relation for the first entity 520 # (instead of the name of its primary key), so that we can 521 # have two many-to-many relations between the same objects 522 # without having a table name collision. 523 source_part = "%s_%s" % (e1_desc.tablename, self.name) 524 525 # And we use the name of the primary key for the second entity 526 # when there is no inverse, so that a many-to-many relation 527 # can be defined without an inverse. 528 if self.inverse: 529 e2_name = self.inverse.name 530 else: 531 e2_name = '_'.join([key.column.name for key in 532 e2_desc.primary_keys]) 533 target_part = "%s_%s" % (e2_desc.tablename, e2_name) 534 535 if self.user_tablename: 536 tablename = self.user_tablename 537 else: 538 # we need to keep the table name consistent (independant of 539 # whether this relation or its inverse is setup first) 540 if self.inverse and e1_desc.tablename < e2_desc.tablename: 541 tablename = "%s__%s" % (target_part, source_part) 542 else: 543 tablename = "%s__%s" % (source_part, target_part) 544 545 # In some databases (at lease MySQL) the constraint names need 546 # to be unique for the whole database, instead of per table. 547 source_fk_name = "%s_fk" % source_part 548 if self.inverse: 549 target_fk_name = "%s_fk" % target_part 550 else: 551 target_fk_name = "%s_inverse_fk" % source_part 552 516 553 columns = list() 517 554 constraints = list() … … 520 557 self.secondaryjoin_clauses = list() 521 558 522 for num, desc, join_name in (('1', e1_desc, 'primary'), 523 ('2', e2_desc, 'secondary')): 559 for num, desc, join_name, fk_name in ( 560 ('1', e1_desc, 'primary', source_fk_name), 561 ('2', e2_desc, 'secondary', target_fk_name)): 524 562 fk_colnames = list() 525 563 fk_refcols = list() … … 550 588 join_list.append(col == pk_col) 551 589 552 # TODO: better constraint-naming?553 590 constraints.append( 554 591 ForeignKeyConstraint(fk_colnames, fk_refcols, 555 name=desc.tablename + '_fk')) 556 557 if self.user_tablename: 558 tablename = self.user_tablename 559 else: 560 # We use the name of the relation for the first entity 561 # (instead of the name of its primary key), so that we can 562 # have two many-to-many relations between the same objects 563 # without having a table name collision. 564 source_part = "%s_%s" % (e1_desc.tablename, self.name) 565 566 # And we use the name of the primary key for the second entity 567 # when there is no inverse, so that a many-to-many relation 568 # can be defined without an inverse. 569 if self.inverse: 570 e2_name = self.inverse.name 571 else: 572 e2_name = '_'.join([key.column.name for key in 573 e2_desc.primary_keys]) 574 target_part = "%s_%s" % (e2_desc.tablename, e2_name) 575 576 # we need to keep the table name consistent (independant of 577 # whether this relation or its inverse is setup first) 578 if self.inverse and e1_desc.tablename < e2_desc.tablename: 579 tablename = "%s__%s" % (target_part, source_part) 580 else: 581 tablename = "%s__%s" % (source_part, target_part) 592 name=fk_name)) 593 582 594 583 595 args = columns + constraints
