add "synchronization" flag to Mapper

Issue #191 resolved
Mike Bayer repo owner created an issue

be able to create a Mapper against a join with custom synchronization rules, in a manner similar to joined table inheritance, except without the inheritance:

account = Table('account',
        Column('id', Integer, primary_key=True),

        Column('email_address', String),
        Column('password', String),
        )

person = Table('person',
        Column('id', Integer, primary_key=True),
        Column('account_id', Integer, ForeignKey('account.id'),

        Column('handle', String),
        Column('firstname', String),
        Column('lastname', String),
        )

class Person(object):
   pass

the mapper then maps against a join of account and person, and synchronizes account_id into the person table:

mapper(Person, join(account, person), synchronize=[account.c.id==person.c.account_id](account.c.id==person.c.account_id))

also, the join of account and person should be able to be in any order. when the mapper does save_obj and delete_obj it should be using the table dependency sort to iterate through the tables.

Comments (7)

  1. Mike Bayer reporter

    hey guess what....i did this functionality so long ago i forgot how it works. i just fixed the docs to illustrate the correct way to do it, and made some small fixes to allow the "many-to-many" version to work, and also got the Mapper to sort the tables correctly when it saves/deletes across multiple, instead of semi-accidentally the way it was working, and cleaned up the unit tests for it.

    the format looks like:

    mapper(Person, join(account, person), properties ={
       'account_id':[person.c.account_id](account.c.account_id,)
    })
    

    and that particular example will work as far back as 0.1.0 !

  2. Log in to comment