Worked like a charm. Thank you for such a prompt reply and for the
project in general.
-brad
On May 22, 6:36 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On May 22, 2008, at 6:10 PM, kremlan wrote:
>
>
>
>
>
> > I have the following setup:
> > (relevant excerpts only)
>
> > contacts = Table('contacts', meta,
> > Column('id', Integer, primary_key=True),
> > Column('display_as', String(75)),
> > Column('title', String(5)),
> > Column('first_name', String(25)),
> > Column('middle_name', String(25)),
> > Column('last_name', String(25)),
> > Column('suffix', String(5)),
> > Column('job_title', String(50)),
> > Column('department', String(50)),
> > Column('company', String(50)),
> > Column('gender', String(1)),
> > Column('website', String(100)),
> > Column('notes', Text),
> > Column('active', Boolean),
> > Column('account_id', Integer),
> > Column('time_zone_id', Integer),
> > Column('created_at', DateTime),
> > Column('updated_at', DateTime),
> > Column('created_by', Integer),
> > Column('updated_by', Integer),
> > ForeignKeyConstraint(['account_id'], ['accounts.id']),
> > ForeignKeyConstraint(['time_zone_id'], ['time_zones.id']),
> > ForeignKeyConstraint(['created_by'], ['contacts.id']),
> > ForeignKeyConstraint(['updated_by'], ['contacts.id'])
> > )
>
> > payment_methods = Table('payment_methods', meta,
> > Column('id', Integer, primary_key=True),
> > Column('contact_id', Integer),
> > Column('payment_method_type_id', Integer),
> > Column('created_at', DateTime),
> > Column('updated_at', DateTime),
> > Column('created_by', Integer),
> > Column('updated_by', Integer),
> > ForeignKeyConstraint(['contact_id'],['contacts.id']),
> > ForeignKeyConstraint(['payment_method_type_id'],
> > ['payment_method_types.id']),
> > ForeignKeyConstraint(['created_by'],['contacts.id']),
> > ForeignKeyConstraint(['updated_by'],['contacts.id']),
> > )
>
> > class Contact(object):
> > pass
>
> > class PaymentMethod(object):
> > pass
>
> > mapper(Contact, contacts, extension=HistoryMapperExtension(),
> > properties={
> > 'payment_methods': relation(PaymentMethod,
> > backref='contact',
>
> > primaryjoin=payment_methods.c.contact_id,
>
> > _local_remote_pairs=[(contacts.c.id, payment_methods.c.contact_id)],
>
> > foreign_keys=[payment_methods.c.contact_id],
>
> > backref='contact')
> > })
>
> > mapper(PaymentMethod, payment_methods)
>
> > A series of exceptions led me to add the primaryjoin, then
> > foreign_keys, then _local_remote_pairs options. Once all three were in
> > place I then received another ArgumentError exception advising I
> > specify a foreign_keys option.
>
> dont use _local_remote_pairs. its underscored because its pretty
> experimental, and i should probably remove it from the error message
> there (im surprised its in there...well there it is...erg).
>
> primaryjoin needs to reference a SQL expression that joins the two
> tables together, as in primaryjoin =
> tablea.c.somecolumn==tableb.c.someothercolumn (this is documented
> here:
> http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relatio...
> ) . Your Table objects already have ForeignKey(Constraint) objects
> set up so that should be all you need.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---