ohhh, I'm out of words other than thank you for spotting it. I can't
believe how stupid I feel right now.
Mariano
Excerpts from Michael Bayer's message of Tue Nov 30 14:27:42 -0300 2010:
> your RegEvent mapper is against the wrong table, here is the correct code:
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
> metadata = MetaData()
>
> regevent = Table('regevent', metadata,
> Column('id', Unicode(200), primary_key=True),
> Column('author', Unicode(200), primary_key=True),
> Column('since', DateTime),
> Column('until', DateTime),
> Column('title', Unicode(100)),
> Column('content', Unicode(600)),
> Column('status', Unicode(200)),
> Column('published', DateTime))
>
> class RegEvent(object):
> pass
>
> regevent_who = Table('regevent_who', metadata,
> Column('id', Integer, primary_key=True,
> autoincrement=True),
> Column('regevent_id', Unicode(200)),
> Column('regevent_author', Unicode(200)),
> Column('email', Unicode(200)),
> Column('status', Unicode(200)),
> Column('role', Unicode(200)),
> ForeignKeyConstraint(("regevent_id", "regevent_author"),
> ("regevent.id", "regevent.author"),
> "regevent_fk"))
>
> class RegEventWho(object):
> pass
>
>
> mapper(RegEvent, regevent, properties={
> 'who': relationship(RegEventWho)
> })
> mapper(RegEventWho, regevent_who)
>
> print Session().query(RegEvent).join(RegEvent.who)
>
> On Nov 30, 2010, at 12:22 PM, Mariano Mara wrote:
>
> > Excerpts from Michael Bayer's message of Tue Nov 30 13:50:26 -0300 2010:
> >> Nothing wrong with the mapping, except the "primaryjoin" is not needed.
> >> The cause is certainly the usage of "useexisting", which implies that
> >> these tables have already been created, and everything you are specifying
> >> in the Table() is ignored. I wouldn't use that flag.
> >>
> >
> > Thanks Michael as always.
> >
> > Removing the useexisting=True, if I also remove the primaryjoin I get:
> >
> > ArgumentError: Could not determine join condition between parent/child
> > tables on relationship RegEvent.who. Specify a 'primaryjoin' expression.
> > If 'secondary' is
> > present, 'secondaryjoin' is needed as well.
> >
> > If I leave the primaryjoin I still get the same error as reported.
> >
> > TIA for any extra ideas you can suggest to fix this.
> >
> > Mariano
> >
> >> On Nov 30, 2010, at 10:22 AM, Mariano Mara wrote:
> >>
> >>> Hi.
> >>>
> >>> I'm trying to relate two tables with a one to many relationship (the
> >>> parent table has a composite primary key) but I'm getting a mapper
> >>> error. I found a recent message about this same problem but with
> >>> declarative base (which I don't use) and not sure why the suggestion
> >>> there didn't apply to my problem.
> >>>
> >>> Find below the error and the table creation code.
> >>>
> >>> TIA,
> >>> Mariano
> >>>
> >>> Error:
> >>>
> >>> ArgumentError: Could not locate any equated, locally mapped column pairs
> >>> for primaryjoin condition 'regevent.id =
> >>> regevent_who.regevent_id AND regevent.author =
> >>> regevent_who.regevent_author' on relationship RegEvent.who. For more
> >>> relaxed rules on join conditions, the relationship may be marked as
> >>> viewonly=True.
> >>>
> >>> Code:
> >>>
> >>> regevent = Table('regevent', metadata,
> >>> Column('id', Unicode(200), primary_key=True),
> >>> Column('author', Unicode(200), primary_key=True),
> >>> Column('since', DateTime),
> >>> Column('until', DateTime),
> >>> Column('title', Unicode(100)),
> >>> Column('content', Unicode(600)),
> >>> Column('status', Unicode(200)),
> >>> Column('published', DateTime),
> >>> useexisting=True)
> >>> Index('regevent_cal_ix', *(regevent.c.calname,))
> >>>
> >>> class RegEvent(object):
> >>> pass
> >>>
> >>> regevent_who = Table('regevent_who', metadata,
> >>> Column('id', Integer, primary_key=True,
> >>> autoincrement=True),
> >>> Column('regevent_id', Unicode(200)),
> >>> Column('regevent_author', Unicode(200)),
> >>> Column('email', Unicode(200)),
> >>> Column('status', Unicode(200)),
> >>> Column('role', Unicode(200)),
> >>> ForeignKeyConstraint(("regevent_id",
> >>> "regevent_author"),
> >>> ("regevent.id",
> >>> "regevent.author"),
> >>> "regevent_fk"),
> >>> useexisting=True)
> >>> Index("regevent_who_fk_ix", *(regevent_who.c.regevent_id,
> >>> regevent_who.c.regevent_author))
> >>>
> >>> class RegEventWho(object):
> >>> pass
> >>>
> >>>
> >>> mapper(RegEvent, regevent_who, properties={
> >>> 'who': relationship(RegEventWho,
> >>> primaryjoin=and_(
> >>> regevent.c.id==regevent_who.c.regevent_id,
> >>>
> >>> regevent.c.author==regevent_who.c.regevent_author))
> >>> })
> >>> mapper(RegEventWho, regevent_who)
> >>>
> >>>
> >>> --
> >>> 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.
> >>>
> >>
> >
> > --
> > 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.
> >
>
--
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.